Pagini recente » Cod sursa (job #3266669) | Cod sursa (job #3247674) | Cod sursa (job #2388249) | Cod sursa (job #1599319) | Cod sursa (job #60220)
Cod sursa(job #60220)
#include <stdio.h>
#define maxn 15010
int a[maxn];
int n,m,x,y,z;
inline int LSB(int x)
{
return (x^(x-1))&x;
}
void update(int x)
{
while (x<=n)
{
a[x]-=y;
x+=LSB(x);
}
}
int query(int x)
{
int rez=0;
while (x>0)
{
rez+=a[x];
x-=LSB(x);
}
return rez;
}
int main()
{
freopen("datorii.in","r",stdin);
freopen("datorii.out","w",stdout);
scanf("%d %d ",&n,&m);
int i;
for (i=1;i<=n;i++)
{
scanf("%d ",&y);
y=-y;
update(i);
}
for (i=1;i<=m;i++)
{
scanf("%d %d %d ",&z,&x,&y);
if (z==0) update(x);
else printf("%d\n",query(y)-query(x-1));
}
return 0;
}