#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long int ll; typedef pair P; random_device rnd; mt19937 mt(rnd()); uniform_real_distribution<> rnd1(0, 1.0); struct node_t{ ll val; node_t *lch; node_t *rch; double pri; int cnt; node_t() {} node_t(ll v, double p):val(v), pri(p), cnt(1), lch(nullptr), rch(nullptr){} }; int count(node_t *t){ return !t ? 0 : t->cnt; } node_t *update(node_t *t){ t->cnt=count(t->lch)+count(t->rch)+1; return t; } node_t *merge(node_t *l, node_t *r){ if(!l || !r) return !l ? r : l; if(l->pri > r->pri){ l->rch=merge(l->rch, r); return update(l); }else{ r->lch=merge(l, r->lch); return update(r); } } pair split(node_t *t, ll x){ if(!t) return make_pair(nullptr, nullptr); if(x <= t->val){ pair s=split(t->lch, x); t->lch=s.second; return make_pair(s.first, update(t)); }else{ pair s=split(t->rch, x); t->rch=s.first; return make_pair(update(t), s.second); } } pair split2(node_t *t, int k){ //[0, k), [k,n) if(!t) return make_pair(nullptr, nullptr); if(k <= count(t->lch)){ pair s=split2(t->lch, k); t->lch=s.second; return make_pair(s.first, update(t)); }else{ pair s=split2(t->rch, k-1-count(t->lch)); t->rch=s.first; return make_pair(update(t), s.second); } } node_t *insert(node_t *t, ll x){ pair s=split(t, x); node_t *u; u=new node_t; *u=node_t(x, rnd1(mt)); return merge(merge(s.first, u), s.second); } node_t *erase(node_t *t, int k){ //erase a[k] pair s=split2(t, k); pair s2=split2(s.second, 1); return merge(s.first, s2.second); } ll find(node_t *t, int k){ //a[k] if(count(t)<=k) return -1; if(count(t->lch)==k){ return t->val; }else if(count(t->lch)rch, k-count(t->lch)-1); }else{ return find(t->lch, k); } } int main() { int q; int k; cin>>q>>k; node_t* s=nullptr; for(int i=0; i>t; if(t==1){ ll x; cin>>x; s=insert(s, x); }else{ ll y=find(s, k-1); cout<=0) s=erase(s, k-1); } } return 0; }