//#pragma warning(disable:4996) //#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include //< in.txt > out.txt using namespace std; //std::ios::sync_with_stdio(false); //std::cin.tie(0); const long long MOD = 1e9 + 7; const long long INF = 1e18; typedef long long LL; typedef long double LD; typedef boost::multiprecision::cpp_int bigint; typedef pair PLL; typedef pair PI; typedef pair pdl; typedef pair pdd; typedef vector VLL; typedef vector VVLL; typedef vector VI; typedef vector> VVI; typedef unsigned long long ULL; template using pqueue = priority_queue, function>; template inline void chmin(T& a, T b) { a = min(a, b); } template inline void chmax(T& a, T b) { a = max(a, b); } void input(); void solve(); void daminput(); void naive(); void outputinput(); int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); input(); //daminput(); solve(); //naive(); //outputinput(); return 0; } ////////////////////////////////////////////////// ////////////////////////////////////////////////// void input() { } void daminput() { } //class Rng { //public: // Rng(); // friend ostream operator<<(ostream&,Rng); (if print neccesary) //}; //Rng operator+(Rng, Rng); class T { public: LL v; T() :v(1e7) {}; T(LL _v) :v(_v) {}; }; T operator+(T a, T b) { if (a.v < b.v)return b; else return a; } //数列タイプのtreap //Xorshift unsigned int Xorshift() { static unsigned int tx = 123456789, ty = 362436069, tz = 521288629, tw = 88675123; unsigned int tt = (tx ^ (tx << 11)); tx = ty; ty = tz; tz = tw; return (tw = (tw ^ (tw >> 19)) ^ (tt ^ (tt >> 8))); } template class node_t { public: Rng val; //値 node_t* ch[2]; //子 LL pri; //優先度 LL cnt; //子の個数 Rng sum; //値の和 static LL node_count; //プール用の要素を数える変数 static const LL MAX_N = 4000000 + 10; //プールのサイズ void* operator new(std::size_t) { static node_t pool[MAX_N]; //プール return pool + node_count++; } static void delete_all() { node_count = 0; } node_t(Rng v) { val = v; ch[0] = ch[1] = NULL; cnt = 1; sum = v; pri = Xorshift(); } node_t() { val = Rng(); ch[0] = ch[1] = NULL; cnt = 1; sum = val; pri = Xorshift(); } node_t* update() { node_t* t = this; t->cnt = (t->ch[0] ? t->ch[0]->cnt : 0) + (t->ch[1] ? t->ch[1]->cnt : 0) + 1; if (t->ch[0])t->sum = t->ch[0]->sum + t->val; else t->sum = t->val; if (t->ch[1])t->sum = t->sum + t->ch[1]->sum; return t; } }; template LL node_t::node_count = 0; //2つのtreapをマージ template node_t* merge(node_t* l, node_t* r) { if (!l || !r)return !l ? r : l; if (l->pri > r->pri) { l->ch[1] = merge(l->ch[1], r); return l->update(); } else { r->ch[0] = merge(l, r->ch[0]); return r->update(); } } //treapを[0,k)と[k,n)にsplit template pair*, node_t*> split(node_t* t, LL k) { typedef pair*, node_t*> P; if (!t)return P(NULL, NULL); LL count = t->ch[0] ? t->ch[0]->cnt : 0; if (k <= count) { P s = split(t->ch[0], k); t->ch[0] = s.second; return P(s.first, t->update()); } else { P s = split(t->ch[1], k - count - 1); t->ch[1] = s.first; return P(t->update(), s.second); } } //treap trの場所kに要素tを追加 template node_t* insert(node_t* tr, LL k, node_t* t) { auto sp = split(tr, k); sp.first = merge(sp.first, t); return merge(sp.first, sp.second); } //treap trの場所kの要素を消去 template node_t* erase(node_t* tr, LL k) { auto sp = split(tr, k); auto sp2 = split(sp.second, 1); //delete sp2.first; return merge(sp.first, sp2.second); } template void print(node_t* root) { if (root == NULL)return; print(root->ch[0]); cout << " " << root->val; print(root->ch[1]); return; } template node_t* index(node_t* root, LL n) { if (!root)return NULL; if (n >= root->cnt)return NULL; LL ln = (root->ch[0] ? root->ch[0]->cnt : 0); LL rn = (root->ch[1] ? root->ch[1]->cnt : 0); if (n < ln)return index(root->ch[0], n); else if (n == ln)return root; else return index(root->ch[1], n - (ln + 1)); } template node_t* change(node_t* root, LL n, Rng x) { if (!root)return NULL; LL ln = (root->ch[0] ? root->ch[0]->cnt : 0); LL rn = (root->ch[1] ? root->ch[1]->cnt : 0); if (n >= ln + rn + 1)return NULL; if (n < ln) { node_t* r = change(root->ch[0], n, x); root->update(); return r; } else if (n == ln) { root->val = x; root->update(); return root; } else { node_t* r = change(root->ch[1], n - (ln + 1), x); root->update(); return r; } } //[l,r] template Rng rangesum(node_t* root, LL l, LL r) { if (root == NULL)return Rng(); LL ln = (root->ch[0] ? root->ch[0]->cnt : 0); LL rn = (root->ch[1] ? root->ch[1]->cnt : 0); if (r < 0 || l > ln + rn)return Rng(); l = max((LL)0, l); r = min(ln + rn, r); if (l == 0 && r == ln + rn)return root->sum; Rng ans = rangesum(root->ch[0], l, r); if (l <= ln && ln <= r)ans = ans + root->val; ans = ans + rangesum(root->ch[1], l - ln - 1, r - ln - 1); return ans; } int Q, K; void solve() { cin >> Q >> K; node_t* node = nullptr; for (int q = 0; q < Q; q++) { int type; cin >> type; if (type == 1) { LL v; cin >> v; if (node == nullptr) { node = new node_t(T(v)); } else { int s = -1, e = node->cnt; while (e - s > 1) { int mid = (e + s) / 2; if (index(node, mid)->val.v < v)s = mid; else e = mid; } node = insert(node, e, new node_t(T(v))); } } else { if (node == nullptr) { cout << -1 << "\n"; } else if (K > (node->cnt)) { cout << -1 << "\n"; } else { auto elem = index(node, K - 1); cout << elem->val.v << "\n"; node = erase(node, K - 1); } } } } void naive() { } void outputinput() { }