Pagini recente » Cod sursa (job #2160641) | Cod sursa (job #3244001) | Cod sursa (job #1726460) | Cod sursa (job #741769) | Cod sursa (job #1730528)
#include <fstream>
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 );
}
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;
j=i;
while(j<=n)
{
bi[j]=bi[j]+a;
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)
{
while(p<=n)
{
bi[p]=bi[p]-q;
p=getnext(p);
}
}
}
fin.close();
fout.close();
return 0;
}