Pagini recente » Cod sursa (job #415213) | Cod sursa (job #3138814) | Cod sursa (job #2724764) | Cod sursa (job #3042098) | Cod sursa (job #306464)
Cod sursa(job #306464)
#include<fstream.h>
ifstream f("datorii.in");
ofstream g("datorii.out");
long a[100001],n,m,i,suma,j,x,y,z;
void php(int x,int poz)
{
int c=0;
while(poz<=n)
{
a[poz]+=x;
while(!(poz&(1<<c))) c++;
poz+=(1<<c);
c+=1;
}
}
void phm(int x,int poz)
{
int c=0;
while(poz<=n)
{
a[poz]-=x;
while(!(poz&(1<<c))) c++;
poz+=(1<<c);
c+=1;
}
}
int func(int poz)
{
int c=0,s=0;
while(poz>=1)
{
s+=a[poz];
while(!(poz&(1<<c))) c++;
poz-=(1<<c);
c+=1;
}
return s;
}
int main()
{
f>>n>>m;
for(i=1;i<=n;i++)
{
f>>x;
php(x,i);
}
for(i=1;i<=m;i++)
{
f>>x;
if(x==0)
{
f>>y>>z;
phm(z,y);
}
if(x==1)
{
f>>y>>z;
g<<(func(z)-func(y-1))<<"\n";
}
}
return 0;
}