-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fenwick update + test point add range sum
- Loading branch information
1 parent
dc7b822
commit bee5f9d
Showing
2 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// @brief Point Add Range Sum | ||
#define PROBLEM "https://judge.yosupo.jp/problem/point_add_range_sum" | ||
#pragma GCC optimize("Ofast,unroll-loops") | ||
#include "cp-algo/structures/fenwick.hpp" | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
void solve() { | ||
int n, q; | ||
cin >> n >> q; | ||
vector<int64_t> a(n + 1); | ||
for(auto &it: a | views::drop(1)) {cin >> it;} | ||
cp_algo::structures::fenwick<int64_t> me(move(a)); | ||
for(int i = 0; i < q; i++) { | ||
int t, x, y; | ||
cin >> t >> x >> y; | ||
if(t == 0) { | ||
me.add(x, y); | ||
} else { | ||
cout << me.range_sum(x, y) << '\n'; | ||
} | ||
} | ||
} | ||
|
||
signed main() { | ||
//freopen("input.txt", "r", stdin); | ||
ios::sync_with_stdio(0); | ||
cin.tie(0); | ||
int t; | ||
t = 1;// cin >> t; | ||
while(t--) { | ||
solve(); | ||
} | ||
} |