Pagini recente » Cod sursa (job #2977843) | Cod sursa (job #989811) | Cod sursa (job #163320) | Cod sursa (job #1991587) | Cod sursa (job #293025)
Cod sursa(job #293025)
#include<stdio.h>
int A[15005],n;
int query(int x)
{
int r = 0;
for (; x; x -= x ^ (x-1) & x)
r += A[x];
return r;
}
void update(int x, int v)
{
for (; x <= n; x += x^(x-1) & x)
A[x] += v;
}
int main()
{
freopen("datorii.in","r",stdin);
freopen("datorii.out","w",stdout);
int m,i,x,y,z;
scanf("%d %d",&n,&m);
for(i=1;i<=n;++i)
scanf("%d",A[i]);
for(i=1;i<=m;++i)
{
scanf("%d %d %d",&x,&y,&z);
if(x==0)
update(y,z);
else if(x==1)
printf("%d\n",query(z)-query(y-1));
}
return 0;
}