Cod sursa(job #785131)

Utilizator stef1995mmarcu stefan ovidiu stef1995m Data 7 septembrie 2012 21:36:48
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include<iostream>
#include<fstream>
using namespace std;
const int maxx=15006;
int n,m,i,x,tip,a,b,aib[maxx];
int pas(int poz)
{
	return poz & (-poz);
}
void update(int poz,int val)
{
	while(poz<=n)
	{
		aib[poz]+=val;
		poz+=pas(poz);
	}
}
int suma(int poz)
{
	int s=0;
	while(poz)
	{
		s+=aib[poz];
		poz-=pas(poz);
	}
	return s;
}
int main()
{
	freopen("datorii.in","r",stdin);
	freopen("datorii.out","w",stdout);
	scanf("%d %d\n",&n,&m);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&x);
		update(i,x);
	}
	for(i=1;i<=m;i++)
	{
		scanf("%d %d %d\n",&tip,&a,&b);
		if(tip==0)
			update(a,-b);
		else
			printf("%d\n",suma(b)-suma(a-1));
	}
	return 0;
}