Cod sursa(job #389344)

Utilizator SzabiVajda Szabolcs Szabi Data 1 februarie 2010 14:44:00
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb

#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;
}