Pagini recente » Cod sursa (job #3321216) | Cod sursa (job #3312794) | Cod sursa (job #3309574) | Cod sursa (job #3309844) | Cod sursa (job #3311592)
#include <bits/stdc++.h>
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));
}
};
int main() {
freopen("datorii.in", "r", stdin);
freopen("datorii.out", "w", stdout);
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 < n; 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';
}
}
}