Pagini recente » Cod sursa (job #402139) | Cod sursa (job #202974) | Cod sursa (job #2274129) | Cod sursa (job #293744) | Cod sursa (job #954848)
Cod sursa(job #954848)
#include<stdio.h>
int n,aib[15010];
int lsb (int x)
{
return x&-x;
}
void update (int pos, int val)
{
for(int i=pos;i<=n;i+=lsb(i))
aib[i]+=val;
}
int query (int pos)
{
int ans=0;
while(pos)
{
ans+=aib[pos];
pos-=lsb(pos);
}
return ans;
}
int main()
{
freopen("datorii.in","r",stdin);
freopen("datorii.out","w",stdout);
int m,tip,p,q,i,j,x;
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
{
scanf("%d",&x);
update(i,x);
}
for(i=1;i<=m;i++)
{
scanf("%d%d%d",&tip,&p,&q);
if(tip==0)
update(p,-q);
else
printf("%d\n",query(q)-query(p-1));
}
return 0;
}