Pagini recente » Cod sursa (job #1587321) | Cod sursa (job #759866) | Cod sursa (job #727869) | Cod sursa (job #2060841) | Cod sursa (job #1764192)
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#define N 15010
using namespace std;
int n;
int arb[N];
void update(int val,int nod){
while(nod<=n){
arb[nod]+=val;
nod=nod+ ( nod ^ ( nod & (nod-1) ) );
}
}
int query(int nod){
static int s;
s=0;
while (nod>0){
s+=arb[nod];
nod = nod&(nod-1);
}
return s;
}
int main(){
int i,m;
int x,y,val,nod;
int spy;
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(x,i);
}
for(i=0;i<m;i++){
scanf("%d",&spy);
if(spy==1){
scanf("%d%d",&x,&y);
y=query(y);
x=query(x-1);
printf("%d\n",y-x);
}else{
scanf("%d%d",&nod,&val);
update(-val,nod);
}
}
return 0;
}