Pagini recente » Cod sursa (job #2798010) | Cod sursa (job #2276229) | Cod sursa (job #314213) | Cod sursa (job #459079) | Cod sursa (job #1730525)
#include <fstream>
#include <iostream>
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
#define dim 100001
long long i,n,m,j,t,q,p,v,s,k,binar,ki,a[dim],bi[dim];
int getparent(int x)
{
return x-( (x ^ (x - 1)) & x );
}
int getnext(int x)
{
return x+( (x ^ (x - 1)) & x );
}
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[i];
for(i=1;i<=n;i++)
{
j=i;
while(j<=n)
{
bi[j]=bi[j]+a[i];
j=getnext(j);
}
}
for(j=1;j<=m;j++)
{
fin>>binar>>p>>q;
if(binar==1)
{
if(p==1)
fout<<suma(q);
else
fout<<suma(q)-suma(p-1);
fout<<"\n";
}
if(binar==0)
{
a[p]=a[p]-q;
while(p<=n)
{
bi[p]=bi[p]-q;
p=getnext(p);
}
}
}
fin.close();
fout.close();
return 0;
}