#include <bits/stdc++.h>
using namespace std;
ifstream f("aib.in");
ofstream g("aib.out");
struct Node
{
Node *st, *dr;
int val, sum, sz, prior;
};
Node nil;
Node *Treap = &nil;
int n,m,v[100005];
Node *mod_fiu(Node *nod, int care, Node *son)
{
if(care==0)
{
nod->st = son;
}
else
{
nod->dr = son;
}
nod->sz = nod->st->sz + 1 + nod->dr->sz;
nod->sum = nod->st->sum + nod->val + nod->dr->sum;
return nod;
}
Node *join(Node *st, Node *dr)
{
if(st==&nil)
{
return dr;
}
if(dr==&nil)
{
return st;
}
if(st->prior>=dr->prior)
{
return mod_fiu(st,1,join(st->dr,dr));
}
return mod_fiu(dr,0,join(st,dr->st));
}
pair<Node*, Node*> split(Node *nod, int k)
{
if(nod==&nil)
{
return {&nil,&nil};
}
if(nod->st->sz>=k)
{
auto t = split(nod->st,k);
return {t.first,mod_fiu(nod,0,t.second)};
}
else
{
auto t = split(nod->dr, k - nod->st->sz - 1);
return {mod_fiu(nod,1,t.first),t.second};
}
}
void Add(int val)
{
Treap = join(Treap,new Node{&nil,&nil,val,val,1,rand()});
}
void update(int poz, int val)
{
auto t = split(Treap,poz);
auto t2 = split(t.first,poz-1);
t2.second->sum+=val;
t2.second->val+=val;
Treap = join(join(t2.first,t2.second),t.second);
}
int query(int a, int b)
{
auto t = split(Treap,b);
auto t2 = split(t.first,a-1);
int rez = t2.second->sum;
Treap = join(join(t2.first,t2.second),t.second);
return rez;
}
int get_poz(int val)
{
int st = 1;
int dr = n;
int poz = -1;
while(st<=dr)
{
int mij = (st+dr)>>1;
int sum = query(1,mij);
if(sum==val)
{
poz = mij;
}
if(sum>=val)
{
dr = mij-1;
}
else
{
st = mij+1;
}
}
return poz;
}
int main()
{
f>>n>>m;
srand(time(NULL));
for(int i=1;i<=n;i++)
{
f>>v[i];
Add(v[i]);
}
for(int i=1;i<=m;i++)
{
int t;
f>>t;
if(t==0)
{
int poz,val;
f>>poz>>val;
update(poz,val);
}
else if(t==1)
{
int a,b;
f>>a>>b;
g<<query(a,b)<<'\n';
}
else if(t==2)
{
int sum;
f>>sum;
g<<get_poz(sum)<<'\n';
}
}
return 0;
}