Pagini recente » Cod sursa (job #2940379) | Cod sursa (job #1921198) | Cod sursa (job #1679728) | Cod sursa (job #2857825) | Cod sursa (job #2189761)
#include <bits/stdc++.h>
#define ll long long
#define sz size
#define pb push_back
#define er erase
#define in insert
#define fr first
#define sc second
#define mp make_pair
#define pi pair
#define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
#define rc(s) return cout<<s,0
#define int long long
const int mod=1e9+7;
const int inf=1e5;
using namespace std;
std::set<int>::iterator it;
std::set<int>::iterator it1;
int aib[100005],lol,m,n,a[100005],t,x,y;
int par(int p);
int binsearch(int l,int r,int x){
while(r>=l){
int mid=l+(r-l)/2;
if(par(mid)>x){
r=mid-1;
continue;
}
if(par(mid)<x){
l=mid+1;
continue;
}
if(par(mid)==x){
return mid;
}
}
return -1;
}
void upd(int v,int g){
while(v<=n){
aib[v]+=g;
v+=v&-v;
}
}
int par(int p){
lol=0;
while(p){
lol+=aib[p];
p-=p&-p;
}
return lol;
}
signed main(){
ifstream fin("aib.in");
ofstream fout("aib.out");
fin >> n >> m;
for(int i=1;i<=n;i++){
fin >> a[i];
upd(i,a[i]);
}
while(m--){
fin >> t;
if(t==0){
fin >> x >> y;
upd(x,y);
continue;
}
if(t==1){
fin >> x >> y;
fout<<par(y)-par(x-1)<<"\n";
continue;
}
if(t==2){
fin >> x;
fout<<binsearch(1,n,x)<<endl;
}
}
}