Pagini recente » Cod sursa (job #1218964) | Cod sursa (job #1981092) | Cod sursa (job #649531) | Cod sursa (job #502840) | Cod sursa (job #1489607)
#include <stdio.h>
#define nmax 15010
using namespace std;
int tip,n,m,i,j,x,y,sol[nmax];
inline int lsb(int x) { return (x&(-x)); }
void build(int x,int y)
{
for (;x<=n;x+=lsb(x)) sol[x]+=y;
}
void update(int x,int y)
{
for (;x<=n;x+=lsb(x)) sol[x]-=y;
}
int query(int x)
{
int soll=0;
for (;x>=1;x-=lsb(x)) soll=soll+sol[x];
return soll;
}
int main() {
freopen("datorii.in","r",stdin);
freopen("datorii.out","w",stdout);
scanf("%d %d",&n,&m);
for (i=1;i<=n;i++) {
scanf("%d",&x); build(i,x);
}
for (i=1;i<=m;i++) {
scanf("%d %d %d",&tip,&x,&y);
if (tip==0) update(x,y); else
printf("%d\n",query(y)-query(x-1));
}
return 0;
}