Pagini recente » Cod sursa (job #1218361) | Cod sursa (job #1239325) | Cod sursa (job #3276712) | Cod sursa (job #2339359) | Cod sursa (job #1182619)
#include<cstdio>
#define LSB(x) ((-x ) & x)
using namespace std;
int AIB[50001],n,m;
void UpDate(int x,int val)
{
for (int i=x;i<=n;i+=LSB(i))
AIB[i]-=val;
}
int Sum(int x)
{
int s=0;
for (int i=x;i>0;i-=LSB(i))
s+=AIB[i];
return s;
}
int main()
{
int i,x,op,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<=n;++i)
{
scanf("%d%d%d",&op,&x,&y);
if (op==0)
{
UpDate(x,y);
}
else
{
printf("%d\n",Sum(y)-Sum(x-1));
}
}
return 0;
}