#include #define rep(i,a,b) for(int i=a;i=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() #pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (boperator()(0, x - 1); } int operator()(int x, int y) { uniform_int_distribution dist(x, y); return dist(mt); } } dc; using V = ll; struct RBST { struct Node { V val; Node *lch, *rch; int sz; Node(V a) :val(a), lch(0), rch(0), sz(1) { init(); } void init() { } void push() { } void update() { } }; RBST() :root(NULL) {} Node *root; inline int getsz(Node *t) { return t ? t->sz : 0; } int getsz() { return getsz(root); } inline void push(Node *t) { if (t == NULL)return; t->push(); } inline Node *update(Node *t) { if (!t)return NULL; t->sz = getsz(t->lch) + getsz(t->rch) + 1; t->update(); return t; } Node *merge(Node *a, Node *b) { push(a); push(b); if (!a)return b; if (!b)return a; if (dc(getsz(a) + getsz(b))rch = merge(a->rch, b); return update(a); } else { b->lch = merge(a, b->lch); return update(b); } } template Node *merge(Node *a, T... y) { return merge(a, merge(y...)); } pairsplit(Node *t, int k) {//[0,k) [k,N) push(t); if (!t)return make_pair(t, t); if (k <= getsz(t->lch)) { pairs = split(t->lch, k); t->lch = s.second; return make_pair(s.first, update(t)); } else { pairs = split(t->rch, k - getsz(t->lch) - 1); t->rch = s.first; return make_pair(update(t), s.second); } } int lower_bound(V x) { return lower_bound(root, x); } int lower_bound(Node *t, V x) { push(t); if (!t)return 0; if (t->val >= x)return lower_bound(t->lch, x); return lower_bound(t->rch, x) + getsz(t->lch) + 1; } // [l,r]番目でa,b,cに分ける(終わったらちゃんとマージすること) // rootは0になってる tuple split3(int l, int r) { auto p = split(root, l); auto a = p.first; auto q = split(p.second, r - l + 1); auto b = q.first; auto c = q.second; root = 0; return make_tuple(a, b, c); } void dump() { dump(root); cout << endl; } void dump(Node *t) { if (t == NULL)return; push(t); dump(t->lch); cout << t->val << " "; dump(t->rch); } void insert(V x) { int k = lower_bound(x); Node *a, *b; tie(a, b) = split(root, k); root = merge(a, new Node(x), b); } void erase(V x) { int k = lower_bound(x); Node *a, *b; tie(a, b) = split(root, k); Node *ba, *bb; tie(ba, bb) = split(b, 1); root = merge(a, bb); } V getAt(int i) { auto p = split(root, i); auto a = p.first; auto q = split(p.second, 1); Node* b = q.first; auto c = q.second; root = merge(merge(a, b), c); return b->val; } }; /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int Q, K; RBST rbst; //--------------------------------------------------------------------------------------------------- void _main() { cin >> Q >> K; rep(q, 0, Q) { int t; cin >> t; if (t == 1) { ll v; cin >> v; rbst.insert(v); } else { int n = rbst.getsz(); if (n < K) printf("-1\n"); else { ll ans = rbst.getAt(K - 1); rbst.erase(ans); printf("%lld\n", ans); } } } }