Pagini recente » Cod sursa (job #3310818) | Cod sursa (job #3304247) | Cod sursa (job #3331941) | Cod sursa (job #3311559) | Cod sursa (job #3309573)
//#include <iostream>
#include <fstream>
using namespace std;
const int maxn = 15005;
ifstream cin("datorii.in");
ofstream cout("datorii.out");
int n, m, x, tip, a, b;
int aib[100005];
int query(int a, int b) {
if(a != 1)
return query(1, b) - query(1, a-1);
int sumaTotala = 0;
while(b > 0) {
sumaTotala += aib[b];
b -= (b & (-b));
}
return sumaTotala;
}
void update(int pos, int val) {
while(pos <= n) {
aib[pos] += val;
pos += (pos & (-pos));
}
}
int main()
{
cin >> n >> m;
for(int i = 1; i <= n; i ++) {
cin >> x;
update(i, x);
}
for(int i = 1; i <= m; i ++) {
cin >> tip;
if(tip == 0) {
cin >> a >> b;
update(a, -b);
} else if(tip == 1) {
cin >> a >> b;
cout << query(a, b) << '\n';
}
}
return 0;
}