#include using namespace std; #define debug(x) cerr << #x << ": " << x << endl #define debugArray(x, n) \ for (long long hoge = 0; (hoge) < (n); ++(hoge)) \ cerr << #x << "[" << hoge << "]: " << x[hoge] << endl struct BinaryIndexedTree { vector dat; BinaryIndexedTree(int n) : dat(n + 1, 0) {} BinaryIndexedTree(int n, long long a) : BinaryIndexedTree(vector(n, a)) {} BinaryIndexedTree(vector y) : dat(y.size() + 1) { for (int k = 0; k < y.size(); ++k) dat[k + 1] = y[k]; for (int k = 1; k + (k & -k) < dat.size(); ++k) dat[k + (k & -k)] += dat[k]; } void add(int k, long long a) { for (++k; k < dat.size(); k += k & -k) dat[k] += a; } // sum [0,k) long long operator[](int k) { long long s = 0; for (; k > 0; k &= k - 1) s += dat[k]; return s; } // min{ k : sum(k) >= a } int lower_bound(long long a) const { int k = 0; for (int p = 1 << (__lg(dat.size() - 1) + 1); p > 0; p >>= 1) if (k + p < dat.size() && dat[k + p] < a) a -= dat[k += p]; return k + 1 == dat.size() ? -1 : k; } }; signed main() { cin.tie(0); ios::sync_with_stdio(0); int Q, K; cin >> Q >> K; vector query; vector x; while (Q--) { long long v; cin >> v; if (v == 1) { cin >> v; x.push_back(v); } else { v = -1; } query.push_back(v); } sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end()); BinaryIndexedTree bit(x.size()); for (auto q : query) { if (q < 0) { int i = bit.lower_bound(K); if (i >= 0) { cout << x[i] << endl; bit.add(i, -1); } else { cout << -1 << endl; } } else { int i = lower_bound(x.begin(), x.end(), q) - x.begin(); bit.add(i, 1); } } }