Pagini recente » Cod sursa (job #1210768) | Cod sursa (job #2669040) | Cod sursa (job #2522413) | Cod sursa (job #1099751) | Cod sursa (job #1088931)
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=15005;
int n,m;
int AIB[MAXN];
int sigma(int pos)
{
int sum=0;
while (pos)
{
sum+=AIB[pos];
pos-= (pos& -pos);
}
return sum;
}
void update(int pos, int val)
{
while (pos<=n)
{
AIB[pos]+=val;
pos+= (pos& -pos);
}
}
int query(int i, int j)
{
return sigma(j)-sigma(i-1);
}
int main()
{
int i,opt,x,y;
freopen("datorii.in","r",stdin);
freopen("datorii.out","w",stdout);
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",&opt,&x,&y);
if (!opt)
update(x,0-y);
else
printf("%d\n",query(x,y));
}
return 0;
}