Pagini recente » Cod sursa (job #428065) | Cod sursa (job #2221994) | Cod sursa (job #1221578) | Cod sursa (job #1391315) | Cod sursa (job #389130)
Cod sursa(job #389130)
#include <stdio.h>
unsigned long n=0,m=0;
unsigned long tree[100001];
unsigned long read( long idx){
unsigned long sum=0;
while (idx>0){
sum+=tree[idx];
idx-=(idx & -idx);
}
return sum;
}
void update( long idx,unsigned long val){
while(idx<=n){
tree[idx]+=val;
idx+= (idx & -idx);
}
}
long elso(unsigned long a){
unsigned long i=1;
bool jo=false;
while((!jo)&&(i<=n)){
if (read(i)==a){jo=true;}else{i++;}
}
if (jo) {return i;}else {return -1;}
}
int main(void){
freopen("aib.in","r",stdin);
freopen("aib.out","w",stdout);
tree[0]=0;
unsigned long i=0,temp,a,b;
scanf("%Ld %Ld",&n,&m);
for(i=1;i<=n;i++){
scanf("%Ld",&temp);
update(i,temp);
}
for(i=1;i<=m;i++){
scanf("%Ld",&temp);
switch(temp){
case 0:
scanf("%Ld %Ld",&a,&b);
update(a,b);
break;
case 1:
scanf("%Ld %Ld",&a,&b);
printf("%Ld\n",read(b)-read(a-1));
break;
case 2:
scanf("%Ld",&a);
printf("%Ld\n",elso(a));
break;
}
}
return 0;
}