Pagini recente » Cod sursa (job #629734) | Cod sursa (job #2828827) | Cod sursa (job #2433278) | Cod sursa (job #2105187) | Cod sursa (job #2189858)
#include <bits/stdc++.h>
#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 arb[100005],m,n,lel,t,x,y;
int sum(int q){
lel=0;
while(q>0){
lel+=arb[q];
q-=(q&-q);
}
return lel;
}
int binsearch(int l,int r,int x){
while(r>=l){
int mid=l+(r-l)/2;
if(sum(mid)>x){
r=mid-1;
continue;
}
if(sum(mid)<x){
l=mid+1;
continue;
}
if(sum(mid)==x){
return mid;
}
}
return -1;
}
void upd(int q,int k){
while(q<=n){
arb[q]+=k;
q+=(q&-q);
}
}
signed main(){ _
ifstream fin("aib.in");
ofstream fout("aib.out");
fin >> n >> m;
for(int i=1;i<=n;i++){
fin >> x;
upd(i,x);
}
for(int j=1;j<=m;j++){
fin >> t;
if(t==0){ fin >> x >> y; upd(x,y); continue;}
if(t==1){ fin >> x >> y; fout<<sum(y)-sum(x-1)<<'\n'; continue; }
if(t==2){ fin >> x; fout<<binsearch(1,n,x)<<'\n'; continue;}
}
}