Pagini recente » Cod sursa (job #2000177) | Cod sursa (job #2604889) | Cod sursa (job #2107631) | Cod sursa (job #1783071) | Cod sursa (job #1505355)
#include <stdio.h>
using namespace std;
const int MAX=150000;
int aib[MAX+1],n;
int ub(int x){
return x & (-x);
}
void update(int poz, int val)
{
if(poz>n)
return;
aib[poz]+=val;
poz+=ub(poz);
update(poz,val);
}
int querry(int poz)
{
int s=0;
while(poz>0)
{
s+=aib[poz];
poz-=ub(poz);
}
return s;
}
int main()
{
freopen("datorii.in","r",stdin);
freopen("datorii.out","w",stdout);
int m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
int val;
scanf("%d",&val);
update(i,val);
}
for(int i=1;i<=m;i++)
{
int op;
int x,y;
scanf("%d%d%d",&op,&x,&y);
if( op==0 )
update(x,-y);
else
printf("%d\n",querry(y)-querry(x-1));
}
return 0;
}