Cod sursa(job #997082)
#include <stdio.h>
#define NMAX 15005
#define MMAX 100005
using namespace std;
int ARB[NMAX],N,M;
int lsb(int x)
{
return -x&x;
}
void pre(int poz,int val)
{
while (poz<=N)
{
ARB[poz]+=val;
poz+=lsb(poz);
}
}
void update(int poz,int val)
{
while (poz<=N)
{
ARB[poz]=ARB[poz]-val;
poz+=lsb(poz);
}
}
int sum(int poz)
{
int s=0;
while (poz)
{
s+=ARB[poz];
poz-=lsb(poz);
}
return s;
}
int main()
{
freopen ("datorii.in","r",stdin);
freopen ("datorii.out","w",stdout);
scanf("%d %d\n",&N,&M);
int i,type,a,b;
for (i=1;i<=N;i++)
{
scanf("%d ",&a);
pre(i,a);
}
for (i=1;i<=M;i++)
{
scanf("%d %d %d\n",&type,&a,&b);
if (!type)
update(a,b);
if (type)
printf("%d\n",sum(b)-sum(a-1));
}
fclose(stdin);
fclose(stdout);
return 0;
}