#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using P = pair; const ll MOD = 998244353; const ll MODx = 1000000007; const int INF = (1<<30)-1; const ll LINF = (1LL<<62LL)-1; const double EPS = (1e-10); P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}}; P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}}; template vector make_vector(size_t a, T b) { return vector(a, b); } template auto make_vector(size_t a, Ts... ts) { return vector(a, make_vector(ts...)); } /* 確認ポイント cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる 計算量は変わらないが楽できるシリーズ min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる */ /* function corner below */ /* Function corner above */ /* comment outed because can cause bugs __attribute__((constructor)) void initial() { cin.tie(0); ios::sync_with_stdio(false); } */ template struct BIT{//1_Indexed int n; vector bit; BIT(int n_):n(n_+1),bit(n_+1,0){} T sum(int a){ int ret = 0; for(int i = a; i > 0; i -= i & -i) ret += bit[i]; return ret; } void add(int a,int w){ for(int i = a; i <= n; i += i & -i)bit[i] += w; //debug(); } T query(int r,int l){ return sum(l-1)-sum(r-1); } int lower_bound(T x){ if(x <= 0){ return 0; } x--; int t = 1; while(t < n)t <<= 1; int st = 0; int base = 0; for(; t; t/=2){ //cout << "D: " << t << " " << st << " " << bit[st+t] << " " << x << endl; if(st+t <= n && base+bit[st+t] <= x){ base += bit[st+t]; st += t; } } //cout << "D: " << st << endl; return st+1; } void debug(){ int nw = 1; int curr = 1; cout << "---begin---" << endl; cout << "D: "; for(int i = 1; n >= i; i++)cout << bit[i] << " "; cout << endl; cout << "---end---" << endl; } }; int main(){ int q,k;cin>>q>>k; set X; vector> l(q); for(int i = 0; q > i; i++){ cin>>l[i].first; if(l[i].first == 1)cin>>l[i].second,X.insert(l[i].second); else l[i].second = -1; } map Z,reZ; int nw = 1; for(auto x: X){ Z[x] = nw; reZ[nw] = x; nw++; } BIT B(X.size()); nw = 0; for(int i = 0; q > i; i++){ if(l[i].first == 1){ B.add(Z[l[i].second],1); nw++; }else{ if(nw < k){ cout << -1 << endl; continue; } auto re = B.lower_bound(k); cout << reZ[re] << endl; B.add(re,-1); nw--; } } }