#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 #include #include #include #include #include #include #include #include /* PascalCase クラス名 camelCase メソッド名,関数名,変数名 snake_case ファイル名,名前空間,std のメソッド名,変数名,型名に準じる場合 SNAKE_CASE マクロ名,static const 定数,列挙体 */ #define REP(i, n) for (int i = 0; i < (n); i++) #define FOR(i, init, n) for(int i = init; i < (n); i++) #define ALL(obj) (obj).begin(), (obj).end() #define RALL(obj) (obj).rbegin(), (obj).rend() #define Cout(obj) cout << obj << endl #define Size(obj) (int)(obj).size() #define fcout cout << fixed << setprecision(10) #define fi first #define se second using namespace std; using ll = long long int; using P = pair; using T = tuple; using edge = struct { int to, cost; }; const int MOD = 1e9 + 7; const int iINF = 1e9; const long long int llINF = 1e18; const double PI = acos(-1.0); const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; template class BIT { private: int N; vector node; public: BIT(int size) { N = size; node.resize(N + 1, 0); } /*[1, a]の合計(1-indexed)*/ T getSum(int i) { T sum = 0; while (i > 0) { sum += node[i]; i -= i & -i; } return sum; } /*[a, b]の合計(1-indexed)*/ T getSum(int l, int r) { T res_l = getSum(l - 1); T res_r = getSum(r); return res_r - res_l; } /*i番目にxを追加(1-indexed)*/ void add(int i, T x) { while (i <= N) { node[i] += x; i += i & -i; } } /* k番目の値を二分探索(0-indexed) */ /* res(0-indexed) */ int lowerBound(int k) { k++; if (k <= 0) { return 0; } int init = 1; while (init < N) { init *= 2; } int res = 0; for (int i = init / 2; i > 0; i /= 2) { if (res + i < N && node[res + i] < k) { k -= node[res + i]; res += i; } } return res + 1; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int Q, K; cin >> Q >> K; int max_Query = 200010; BIT bit(max_Query); vector T(Q); vector V(Q); vector queries; REP(i, Q) { cin >> T[i]; if (T[i] == 1) { cin >> V[i]; queries.push_back(V[i]); } } sort(ALL(queries)); queries.erase(unique(ALL(queries)), queries.end()); REP(i, Q) { if(T[i] == 1) { int index = lower_bound(ALL(queries), V[i]) - queries.begin(); index++; bit.add(index, 1); } else { int size = bit.getSum(max_Query); if(K > size) { cout << -1 << endl; } else { int value = bit.lowerBound(K - 1); cout << queries[value - 1] << endl; bit.add(value, -1); } } } return 0; }