mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 17:28:47 +00:00
B - Fenwick Tree
https://atcoder.jp/contests/practice2/submissions/33500324
This commit is contained in:
parent
d3eb18bfdd
commit
133b6d9da5
40
AtCoder/practice2/B/B.cpp
Normal file
40
AtCoder/practice2/B/B.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#include <iostream>
|
||||
#include <atcoder/fenwicktree>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int n, q;
|
||||
|
||||
cin >> n >> q;
|
||||
|
||||
atcoder::fenwick_tree<long long> tr(n);
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
long long x;
|
||||
|
||||
cin >> x;
|
||||
|
||||
tr.add(i, x);
|
||||
}
|
||||
|
||||
while (q--) {
|
||||
int op;
|
||||
long long x, y;
|
||||
|
||||
cin >> op >> x >> y;
|
||||
|
||||
if (op == 0) {
|
||||
tr.add(x, y);
|
||||
} else { // op == 1
|
||||
cout << tr.sum(x, y) << endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user