Pagini recente » Cod sursa (job #568497) | Cod sursa (job #13230) | Cod sursa (job #2114323) | Cod sursa (job #2191604) | Cod sursa (job #1181116)
#include<cstdio>
const int N=15000;
int tree[N*2+1];
int n,t;
FILE*in=fopen("datorii.in","r");
FILE*out=fopen("datorii.out","w");
void updateTree(int p,int val){
while(p<=n){
tree[p]-=val;
p+=p&-p;
}
}
void scan(){
int i,no;
fscanf(in,"%d%d",&n,&t);
for(i=1;i<=n;i++){
fscanf(in,"%d",&no);
updateTree(i,-no);
}
}
int sum(int p){
int s=0;
while(p>0){
s+=tree[p];
p-=p&-p;
}
return s;
}
int main(){
int type,p,v,x,y;
scan();
while(t!=0){
fscanf(in,"%d",&type);
if(type==0){
fscanf(in,"%d%d",&p,&v);
updateTree(p,v);
}
else{
fscanf(in,"%d%d",&x,&y);
fprintf(out,"%d\n",sum(y)-sum(x-1));
}
t--;
}
return 0;
}