Cod sursa(job #643408)

Utilizator d.andreiDiaconeasa Andrei d.andrei Data 3 decembrie 2011 17:36:18
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <cstdio>

#define file_in "datorii.in"
#define file_out "datorii.out"

#define lsb(x) ((x)&(-(x)))

int N,M,tip,a,b,X;
int Aib[101000];

void add(int poz, int val){
	
	int i;
	for (i=poz;i<=N;i+=lsb(i))
		 Aib[i]+=val;
}

int sol(int poz){
	
	int i,ans=0;
	for (i=poz;i>=1;i-=lsb(i))
		 ans+=Aib[i];
	return ans;
}

int main(){
	
	int i;
	freopen(file_in,"r",stdin);
	freopen(file_out,"w",stdout);
	
	scanf("%d %d", &N, &M);
	for (i=1;i<=N;++i){
		  scanf("%d", &X);
		  add(i,X);
	}
	
	while(M--){
		scanf("%d %d %d", &tip,&a, &b);
		if (tip==0)
			add(a,-b);
		else
			printf("%d\n", sol(b)-sol(a-1));
	}
	
	return 0;
	
}