Pagini recente » Cod sursa (job #2596629) | Cod sursa (job #2891433) | Cod sursa (job #772750) | Cod sursa (job #835219) | Cod sursa (job #1730530)
#include <fstream>
#include <iostream>
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
#define MAX 100001
#define dim 100001
long long i,n,m,j,t,q,p,v,s,k,binar,a,ki,bi[dim];
int getparent(int x)
{
return x-( (x ^ (x - 1)) & x );
}
int getnext(int x)
{
return x+( (x ^ (x - 1)) & x );
}
void up(int x,int y)
{
j=x;
while(j<=n)
{
bi[j]=bi[j]+y;
j=getnext(j);
}
}
int suma(int x)
{
if(x==0)
return 0;
else
return bi[x]+bi[getparent(x)];
}
int main()
{
fin>>n>>m;
for(i=1;i<=n;i++)
{
fin>>a;
up(i,a);
}
for(i=1;i<=m;i++)
{
fin>>binar>>p>>q;
if(binar==1)
{
if(p==1)
fout<<suma(q);
else
fout<<suma(q)-suma(p-1);
fout<<"\n";
}
else
up(p,-q);
}
fin.close();
fout.close();
return 0;
}