Pagini recente » Cod sursa (job #628943) | Cod sursa (job #390068) | Cod sursa (job #886969) | Cod sursa (job #1881079) | Cod sursa (job #469570)
Cod sursa(job #469570)
#include<cstdio>
#define N 1<<14
int n,m,aib[N];
int bit(int x)
{
return (x&(x-1))^x;
}
void update(int poz,int x)
{
while(poz<=n)
{
aib[poz]-=x;
poz+=bit(poz);
}
}
int suma(int poz)
{
int s=0;
while(poz)
{
s+=aib[poz];
poz-=bit(poz);
}
return s;
}
int main()
{
freopen("datorii.in","r",stdin);
freopen("datorii.out","w",stdout);
scanf("%d%d",&n,&m);
int x,y,t;
for(int i=1;i<=n;i++)
{
scanf("%d",&x);
update(i,-x);
}
for(int i=1;i<=m;i++)
{
scanf("%d",&t);
if(t==0)
{
scanf("%d%d",&x,&y);
update(x,y);
continue;
}
scanf("%d%d",&x,&y);
printf("%d\n",suma(y)-suma(x-1));
}
return 0;
}