Cod sursa(job #456694)

Utilizator siminescuPaval Cristi Onisim siminescu Data 16 mai 2010 14:24:18
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.57 kb
#include<fstream>
using namespace std;
ifstream f("datorii.in");
ofstream g("datorii.out");
#define nmax 15002
int v,s[nmax],n,m,t,p,q;
void A()
{
	while(t<=n)
	{
		s[t]-=v;t+=(t&-t);
	}
}
void citire()
{
	f>>n>>m;int i;
	for(i=1;i<=n;i++)
	{
		f>>v;t=i;
		while(t<=n)
		{
			s[t]+=v;t+=(t&-t);
		}
	}
}
long long suma(int i)
{
	long long sum=0;
	while(i)
	{
		sum+=s[i];i-=(i&-i);
	}
	return sum;
}
int main()
{
	citire();
	int x;
	for(;m;--m)
	{
		f>>x;
		if(x==0) {f>>t>>v;A();}
		if(x==1) {f>>p>>q;g<<suma(q)-suma(p-1)<<'\n';}
	}
}