Cod sursa(job #306963)

Utilizator pcinfoCarmen Popescu pcinfo Data 22 aprilie 2009 15:55:23
Problema Datorii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <fstream>
#include <vector>

using namespace std;

ifstream f("datorii.in");
ofstream g("datorii.out");

using namespace std;

int n;

void modif(int poz,int x,vector<int> a)
{	int c,j;
	a[poz]+=x;
	do
	{
		c=poz;
		j=0;
		while (poz%2==0)
		{	
			poz=poz/2;
			j++;
		}
		poz=c+(1<<j);
		if (poz<=n)
			a[poz]+=x;
		else
			return;
	}while (1);
}

int sum(int x)
{
}

int main()
{
	int m,i,x,y,c,j;
	
	f>>n>>m;
	
	vector<int> b(n+1,0);
	
	
	for (i=1;i<=n;i++)
	{
		f>>x;
		modif(i,x,b);
		
	}
	
	for (i=1;i<=m;i++)
	{
		f>>c>>x>>y;
		if (c==0)
			modif(x,-y,b);
		else
			g<<sum(y)-sum(x-1);
	}

	f.close();
	g.close();
	
	return 0;
}