Cod sursa(job #429936)

Utilizator za_wolfpalianos cristian za_wolf Data 30 martie 2010 17:08:52
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
//#include "stdafx.h"
#include<stdio.h>
#define NMAX 15100
int x[NMAX],i,a,b,c,m,n,p;
int zero(int a)
{
	return (a&(a-1)^a);
}
void tip1(int a,int p)
{
	while (p<=n)
	{
		x[p]-=a;
		p+=zero(p);
	}
}
int tip2(int p)
{
	int s=0;
	while (p)
	{
		s+=x[p];
		p-=zero(p);
	}
	return s;
}
int main()
{
	freopen("datorii.in","r",stdin);
	freopen("datorii.out","w",stdout);
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;i++)
	{
		scanf("%d",&a);
		tip1(-a,i);
	}
	for (i=1;i<=m;i++)	
	{
		scanf("%d%d%d",&a,&b,&c);
		if (a)
			printf("%d\n",tip2(c)-tip2(b-1));
		else
			tip1(c,b);
	}

	return 0;
}