Cod sursa(job #954861)

Utilizator thewildnathNathan Wildenberg thewildnath Data 30 mai 2013 11:51:41
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include<stdio.h>

int n,aib[15005];

inline int lsb(int x)
{
	return ((x^(x-1))+1)>>1;
}

void update(int pos,int val)
{
	int i;
	for(i=pos;i<=n;i+=lsb(i))
		aib[i]+=val;
}

int query(int pos)
{
	int ans=0;
	while(pos)
	{
		ans+=aib[pos];
		pos-=lsb(pos);
	}
	return ans;
}

int main()
{
	freopen("datorii.in","r",stdin);
	freopen("datorii.out","w",stdout);
	int m,i,x,a,b;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&x);
		update(i,x);
	}
	for(i=1;i<=m;i++)
	{
		scanf("%d%d%d",&x,&a,&b);
		if(x==0)
			update(a,-b);
		else
			printf("%d\n",query(b)-query(a-1));
	}
	return 0;
}