#include #define rep(i, n) for(int(i) = 0; (i) < (n); (i)++) #define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++) #define ALL(v) (v).begin(), (v).end() #define LLA(v) (v).rbegin(), (v).rend() #define SZ(v) (v).size() #define INT(...) \ int __VA_ARGS__; \ read(__VA_ARGS__) #define LL(...) \ ll __VA_ARGS__; \ read(__VA_ARGS__) #define DOUBLE(...) \ double __VA_ARGS__; \ read(__VA_ARGS__) #define CHAR(...) \ char __VA_ARGS__; \ read(__VA_ARGS__) #define STRING(...) \ string __VA_ARGS__; \ read(__VA_ARGS__) #define VEC(type, name, size) \ vector name(size); \ read(name) using namespace std; using ll = long long; using pii = pair; using pll = pair; using Graph = vector>; template struct edge { int to; T cost; edge(int t, T c) : to(t), cost(c) {} }; template using WGraph = vector>>; const int INF = 1 << 30; const ll LINF = 1LL << 60; const int MOD = 1e9 + 7; template inline vector make_vec(size_t a, T val) { return vector(a, val); } template inline auto make_vec(size_t a, Ts... ts) { return vector(a, make_vec(ts...)); } void read() {} template inline void read(T &a) { cin >> a; } template inline void read(pair &p) { read(p.first), read(p.second); } template inline void read(vector &v) { for(auto &a : v) read(a); } template inline void read(Head &head, Tail &...tail) { read(head), read(tail...); } template inline void chmax(T &a, T b) { (a < b ? a = b : a); } template inline void chmin(T &a, T b) { (a > b ? a = b : a); } /** * @brief 0-indexed (Internally 1-indexed) Fenwick Tree * * @tparam T Universal set. */ template struct FenwickTree { int n; vector dat; FenwickTree(int n) : n(++n), dat(n, 0) {} void add(int i, T x) { for(++i; i < n; i += i & -i) dat[i] = dat[i] + x; } /** * @brief Sum values in [0,i] * * @param i Right end of interval. Note that closed-interval [0,i]. * @return T Summation values in [0,i]. */ T sum(int i) { T res = 0; for(++i; i > 0; i -= i & -i) { res = res + dat[i]; } return res; } /** * @brief Sum values in [l,r] * * @param l Left end of interval. * @param r Right end of interval. * @return T Summation values in [l,r] */ T sum(int l, int r) { return sum(r) - sum(l - 1); } /** * @brief Sum all values. * * @return T Summation values. */ T sumAll() { return sum(n - 1); } /** * @brief If regard as histogram of elements, get k-th element. * * @param k Get k-th element. * @return int Index to which k-th element belongs. */ int get(T k) { ++k; int res = 0; int N = 1; while(N < n) N *= 2; for(int i = N / 2; i > 0; i /= 2) { if(res + i < n && dat[res + i] < k) { k = k - dat[res + i]; res = res + i; } } return res + 1; } }; /** * @brief 座標圧縮 * * @tparam T データ型 * @param X 圧縮する数列 副作用により圧縮後の値が入る * @return std::vector ソートして重複を除去した元数列 */ template std::vector compress(std::vector &X) { std::vector vals = X; std::sort(vals.begin(), vals.end()); vals.erase(unique(vals.begin(), vals.end()), vals.end()); for(int i = 0; i < X.size(); i++) { X[i] = lower_bound(vals.begin(), vals.end(), X[i]) - vals.begin(); } return vals; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); INT(q, k); FenwickTree bit(200010); vector query(q); vector vals; rep(i, q) { INT(a); if(a == 1) { LL(v); query[i] = {a, v}; vals.emplace_back(v); } else { query[i] = {a, 0}; } } auto dict = compress(vals); int now = 0; for(auto [a, v] : query) { if(a == 1) { bit.add(vals[now++], 1); } else { if(bit.sumAll() < k) { cout << -1 << endl; } else { int val = bit.get(k - 1); cout << dict[val - 1] << endl; bit.add(val - 1, -1); } } } }