Pagini recente » Cod sursa (job #3303999) | Cod sursa (job #3311597)
#include <bits/stdc++.h>
#define int long long
using namespace std;
int lsb(int x) {
return x & (-x);
}
struct AIB {
vector<int> a;
int n;
AIB(int N) {
n = N;
a.resize(n);
}
void update(int p, int val) {
if(p > n)
return;
a[p - 1] += val;
update(p + lsb(p), val);
}
int pf(int p) {
if(p <= 0)
return 0;
return a[p - 1] + pf(p - lsb(p));
}
};
signed main() {
freopen("datorii.in", "r", stdin);
freopen("datorii.out", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, q; cin >> n >> q;
AIB aib(n);
for(int i = 0; i < n; i ++) {
int x; cin >> x;
aib.update(i + 1, x);
}
for(int i = 0; i < q; i ++) {
int cer; cin >> cer;
if(cer == 0) {
int p, val; cin >> p >> val;
aib.update(p, -val);
} else {
int st, dr; cin >> st >> dr; st --;
cout << aib.pf(dr) - aib.pf(st) << '\n';
}
}
}