Pagini recente » Cod sursa (job #793501) | Cod sursa (job #2266198) | Cod sursa (job #762193) | Cod sursa (job #2054505) | Cod sursa (job #428403)
Cod sursa(job #428403)
#include <stdio.h>
#define NMAX 15010
int t[NMAX];
int n, m;
void update(int x, int poz){
int C = 0;
while(poz <= n){
t[poz] += x;
while( !((1<<C) & poz)) C++;
poz += (1<<C);
C++;
}
}
int query(int poz){
int C = 0, s = 0;
while(poz){
s += t[poz];
while( ! ((1<<C) & poz)) C++;
poz -= (1<<C);
C++;
}
return s;
}
int main(){
freopen("datorii.in", "r", stdin);
freopen("datorii.out", "w", stdout);
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; ++i){
int x;
scanf("%d", &x);
update(x, i);
}
for(int i = 1; i <= m; ++i){
int x, y, cod;
scanf("%d%d%d", &cod, &x, &y);
if(cod)
printf("%d\n", query(y) - query(x-1));
else update(-y, x);
}
return 0;
}