Pagini recente » Cod sursa (job #3327105) | Cod sursa (job #3156033) | Cod sursa (job #1446308) | Cod sursa (job #278425) | Cod sursa (job #3337575)
#include <algorithm>
#include <fstream>
#include <vector>
#include <queue>
#include <iostream>
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
#define cin fin
#define cout fout
int n, m;
int a[15001];
int fenwick[15001];
void update(int node, int val) {
for(int i = node; i <= n; i += (i&-i)) {
fenwick[i] += val;
}
}
long long query(int node) {
long long ans=0;
for(int i = node; i > 0; i-=(i&-i)) {
ans += fenwick[i];
}
return ans;
}
int main()
{
cin >> n >> m;
for(int i = 1; i <= n; i++) {
cin >> a[i];
update(i, a[i]);
}
for(int i = 1; i <= m; i++) {
int op, x, y;
cin >> op >> x >> y;
if (op==0) {
a[x] -= y;
update(x, -y);
} else {
cout << query(y) - query(x-1) << "\n";
}
}
return 0;
}