Pagini recente » Cod sursa (job #1618077) | Cod sursa (job #2001390) | Cod sursa (job #940464) | Autentificare | Cod sursa (job #389344)
Cod sursa(job #389344)
#include <stdio.h>
unsigned int n,m;
unsigned int tree[15001];
void update( int idx, int val)
{
while(idx<=n){
tree[idx]+=val;
idx+=(idx & -idx);
}
}
int read(int idx){
int sum=0;
while(idx>0){
sum+=tree[idx];
idx-=(idx & -idx);
}
return sum;
}
int main(){
int i,temp,a,b;
freopen("datorii.in","r",stdin);
freopen("datorii.out","w",stdout);
scanf("%d %d",&n,&m);
for (i=1;i<=n;i++){
scanf("%d",&temp);
update(i,temp);
}
for(i=1;i<=m;i++){
scanf("%d %d %d",&temp,&a,&b);
if(!temp){
update(a,-b);
}else{
printf("%d\n",read(b)-read(a-1));
}
}
return 0;
}