Pagini recente » Cod sursa (job #1626781) | Cod sursa (job #2600935) | Cod sursa (job #179105) | Cod sursa (job #1697833) | Cod sursa (job #1512191)
#include <cstdio>
using namespace std;
const int nmx = 15003;
int n,m,arb[nmx];
int pow2(int nr){
return ((nr^(nr-1))&nr);
}
void update(int pos, int val){
while(pos <= n){
arb[pos] += val;
pos += pow2(pos);
}
}
void citire(){
scanf("%d %d", &n, &m);
int nr;
for(int i = 1; i <= n; ++i){
scanf("%d", &nr);
update(i,nr);
}
}
int query(int pos){
int sum = 0;
while(pos){
sum += arb[pos];
pos -= pow2(pos);
}
return sum;
}
int main(){
freopen("datorii.in", "r", stdin);
freopen("datorii.out", "w", stdout);
citire();
int a,b,c;
for(int i = 1; i <= m; ++i){
scanf("%d %d %d", &c, &a, &b);
if(not c)
update(a,-b);
else
printf("%d\n", query(b) - query(a-1));
}
return 0;
}