#ifndef LOCAL #include using namespace std; #define debug(...) (void(0)) #else #include "algo/debug.h" #endif template struct FenwickTree { private: int n; int pw; std::vector dat; public: FenwickTree(int m = 0) { init(m); } void init(int m) { n = m; pw = std::bit_floor((unsigned int)n); dat.assign(n, T{}); } void add(int p, const T& x) { assert(0 <= p && p < n); for (p += 1; p <= n; p += p & -p) { dat[p - 1] += x; } } T sum(int l, int r) const { assert(0 <= l && l <= r && r <= n); return sum(r) - sum(l); } int select(T x) const { int at = 0; for (int len = pw; len > 0; len >>= 1) { if (at + len <= n && dat[at + len - 1] <= x) { at += len; x -= dat[at - 1]; } } assert(0 <= at && at <= n); return at; } private: T sum(int r) const { T ans{}; for (; r > 0; r -= r & -r) { ans += dat[r - 1]; } return ans; } }; void solve() { int Q, K; cin >> Q >> K; FenwickTree fw(Q); vector> Qs(Q); vector cc; for (int i = 0; i < Q; i++) { int64_t o, v = -1; cin >> o; if (o == 1) { cin >> v; cc.push_back(v); } Qs[i] = {o, v}; } sort(cc.begin(), cc.end()); cc.erase(unique(cc.begin(), cc.end()), cc.end()); for (int i = 0; i < Q; i++) if (Qs[i].first == 1) Qs[i].second = distance(cc.begin(), lower_bound(cc.begin(), cc.end(), Qs[i].second)); int sz = 0; for (int i = 0; i < Q; i++) { auto [o, v] = Qs[i]; if (o == 1) { sz++; fw.add(v, 1); } else { if (sz >= K) { int id = fw.select(K - 1); cout << cc[id] << endl; sz--; fw.add(id, -1); } else { cout << -1 << endl; } } } } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int tt = 1; // std::cin >> tt; while (tt--) { solve(); } }