Pagini recente » Cod sursa (job #2916781) | Cod sursa (job #2909493) | Cod sursa (job #1204452)
#include <cstdio>
using namespace std;
int N,i,Q,val,AIB[15005];
void Update(int poz,int val)
{
for (;poz<=N;poz+=poz&-poz) AIB[poz]-=val;
}
int Query(int poz)
{
int sum=0;
for (;poz>0;poz-=poz&-poz) sum+=AIB[poz];
return sum;
}
int main()
{
freopen("datorii.in","r",stdin);
freopen("datorii.out","w",stdout);
scanf("%d %d",&N,&Q);
for (i=1;i<=N;i++) scanf("%d",&val),Update(i,-val);
while (Q--)
{
int op,x,y;
scanf("%d %d %d",&op,&x,&y);
if (op) printf("%d\n",Query(y)-Query(x-1));
else Update(x,y);
}
return 0;
}