Cod sursa(job #385119)

Utilizator Alexa_ioana_14Antoche Ioana Alexandra Alexa_ioana_14 Data 22 ianuarie 2010 08:37:56
Problema Datorii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.04 kb
#include<cstdio>
#define N 15001
void build (int nod, int l,int r)
{
	if (l==r)
	{
		a[nod]=v[l];
		return;
	}
	int m=(l+r)>>1;
	build(2*nod,l,m);
	build(2*nod+1,m+1,r);
	a[nod]=a[2*nod]+a[2*nod+1];
}
void update(int nod, int l,int r,int poz, int val)
{
	if (l==r)
	{
		a[nod]=val;
		return;
	}
	int m=(l+r)>>1;
	if (l<=poz)
		update(2*nod,l,m,poz,val);
	else
	if (l<r)
	update(2*nod+1,m+1,r,poz,val);
	a[nod]=a[2*nod]+a[2*nod+1];
}
int suma(int nod, int l, int r,int a, int b)
{
	if (a<=l&&r<=b)
		return a[nod];
	int m=(l+r)>>1,i1=0,i2=0;
	if (a<=m)
		i1=suma(2*nod,l,m,a,m);
	if (b>m)
		i2=suma(2*nod+1,m+1,r,m+1,b);
	return i1+r2;
}
void citire()
{
	freopen("datorii.in","r",stdin);
	freopen("datorii.out","w",stdout);
	scanf("%d%d",&n,&m);
	int i;
	for (i=1; i<=n; ++i)
	scanf("%d",&v[i]);
	build(1,1,n);
	while (m--)
	{
		scanf("%d%d%d",&q,&a,&b);
		if (!q)
		{
			val=v[a]-b;
			update(1,1,n,a,val);
		}
		else
		{
			printf("%d",suma(1,1,n,a,b));
		}
	}
}
int main()
{
	citire();
	return 0;
}