Pagini recente » Cod sursa (job #461092) | Monitorul de evaluare | Cod sursa (job #1278386) | Cod sursa (job #242938) | Cod sursa (job #1246244)
#include <cstdio>
#define NRM 15000
using namespace std;
long n,m,i,l,val,ind,poz,x,dr,st,s1,s2;
long a[NRM];
long query(long x)
{
long s = 0;
for (; x; x -= x ^ (x-1) & x)
s += a[x];
return s;
}
void update(long x, long v)
{
for (; x <= n; x += x^(x-1) & x)
a[x] += v;
}
int main(){
freopen("datorii.in","r",stdin);
freopen("datorii.out","w",stdout);
scanf("%ld %ld",&n,&m);
for (i=1;i<=n;i++){
scanf("%ld",&val);
update(i,val);
}
for(i=1;i<=m;i++)
{
scanf ("%ld",&l);
if(l==1){
scanf("%ld %ld",&st,&dr);
s1=query(dr);
s2=query(st-1);
printf("%ld\n",s1-s2);
}
else{
scanf("%ld %ld",&ind,&val);
val=val*-1;
update(ind,val);
}
}
printf("\n");
return 0;
}