Pagini recente » Cod sursa (job #1247656) | Cod sursa (job #2785144)
#include<fstream>
using namespace std;
ifstream F("datorii.in");
ofstream G("datorii.out");
int m,s,t[15001];
short n,x,y,k;
bool c;
char e[4096];
int B()
{
int r=0;
while(e[k]<'0'||e[k]>'9')
if(++k==4096)
F.read(e,4096),k=0;
for(;'0'<=e[k]&&e[k]<='9';) {
r=(r<<1)+(r<<3)+e[k]-'0';
if(++k==4096)
F.read(e,4096),k=0;
}
return r;
}
int main()
{
for(n=B(),m=B(),y=1;y<=n;++y)
for(x=B(),s=y;s<=n;t[s]+=x,s+=(s&-s));
while(m--) {
c=B(),x=B(),y=B();
if(c) {
for(s=0;y;s+=t[y],y-=(y&-y));
for(--x;x;s-=t[x],x-=(x&-x));
o<<s<<'\n';
} else
for(;x<=n;t[x]-=y,x+=(x&-x));
}
return 0;
}