Pagini recente » Cod sursa (job #926643) | Cod sursa (job #2326317) | Cod sursa (job #1269425) | Cod sursa (job #1898190) | Cod sursa (job #1719809)
#include <cstdio>
#include <algorithm>
#define MAX 6000000
#define MAXN 100005
#define INF 2000000005
using namespace std;
char f[MAX];
int pos=0,M,N,v[33000],Type,V1,V2,h=1,sp=1;
void r(int &nr)
{
nr=0;
while(f[pos]<'0'||f[pos]>'9')
pos++;
while(f[pos]>='0'&&f[pos]<='9')
nr=nr*10+f[pos++]-'0';
}
int POW(int el,int exp)
{
int ret=1;
for(int i=1;i<=exp;i++)
ret*=el;
return ret;
}
int getsum(int pos)
{
int Sum=0,i=sp+pos-1;
while(i>1)
{
if(i%2==1)
Sum+=v[i-1];
i/=2;
}
return Sum;
}
int main()
{
freopen("datorii.in","r",stdin);
freopen("datorii.out","w",stdout);
fread(f,1,MAX,stdin);
r(N);r(M);
while(sp<N)
sp*=2,h++;
for(int i=0;i<N;i++)
{
r(v[sp+i]);
int P=sp+i;
while(P>1)
{
v[P/2]+=v[sp+i];
P/=2;
}
}
for(int i=1;i<=M;i++)
{
r(Type);r(V1);r(V2);
if(Type==0)
{
int P=sp+V1-1;
while(P>1)
{
v[P]-=V2;
P/=2;
}
}
else
{
printf("%d\n",getsum(V2)-getsum(V1)+v[sp+V2-1]);
}
}
return 0;
}