# 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 #include //#include using namespace std; using LL = long long; using ULL = unsigned long long; long long MOD = 1000000000+7; constexpr long long INF = numeric_limits::max(); const double PI = acos(-1); #define fir first #define sec second #define thi third #define debug(x) cerr<<#x<<": "< Pll; typedef pair> Ppll; typedef pair>> Pbll; typedef pair>> Pvll; typedef pair Vec2; struct Tll { LL first, second, third; }; typedef pair Ptll; #define rep(i,rept) for(LL i=0;i=0;i--) LL h, w, n, m, k, t, s, q, last, cnt, sum[2000000], ans, d[200000], a[2000000], b[2000000]; string str,ss; int f[26][26]; char c; int di[4][2] = { { 0,1 },{ 1,0 },{ -1,0 } ,{ 0,-1 } }; struct Edge { LL to, cost; }; vectorvec[26]; vectorv; mapma; setst; void YN(bool f) { if (f) cout << "YES" << endl; else cout << "NO" << endl; } void yn(bool f) { if (f) cout << "Yes" << endl; else cout << "No" << endl; } // // a[0],a[1],a[2],...,a[k],... // template struct node_t { T val; // 値 node_t *lch; node_t *rch; double pri; // 優先度 int cnt; // 部分木のサイズ T min_val; T lazy_val; bool lazy; node_t(T v, double p) : val(v), lch(nullptr), rch(nullptr), pri(p), cnt(1), min_val(v), lazy_val(0), lazy(false) {} ~node_t() { delete lch; delete rch; } static void push(node_t *t) { if (!t) return; if (t->lazy) { t->val += t->lazy_val; t->min_val += t->lazy_val; if (t->lch) { t->lch->lazy = true; t->lch->lazy_val += t->lazy_val; } if (t->rch) { t->rch->lazy = true; t->rch->lazy_val += t->lazy_val; } t->lazy_val = 0; t->lazy = false; } } static int count(node_t *t) { return t ? t->cnt : 0; } static int Min(node_t *t) { return t ? t->min_val : std::numeric_limits::max(); } static node_t *update(node_t *t) { assert(t != nullptr); push(t); t->cnt = count(t->lch) + count(t->rch) + 1; push(t->lch); push(t->rch); t->min_val = std::min({ (T)Min(t->lch), (T)Min(t->rch), t->val }); return t; } static node_t *merge(node_t *l, node_t *r) { if (!l || !r) return (!l) ? r : l; update(l); update(r); if (l->pri > r->pri) { l->rch = merge(l->rch, r); return update(l); } else { r->lch = merge(l, r->lch); return update(r); } assert(false); return nullptr; } // // node をたどることになる。k番目のノードで再帰が止まる // [0,1,2,...,k-1,k,...] // -> [0,1,2,...,k-1] [k,...] // static std::pair split(node_t* t, int k) { if (!t) return std::make_pair(nullptr, nullptr); update(t); if (k <= count(t->lch)) { auto s = split(t->lch, k); t->lch = s.second; return std::make_pair(s.first, update(t)); } else { auto s = split(t->rch, k - count(t->lch) - 1); t->rch = s.first; return std::make_pair(update(t), s.second); } assert(false); return std::make_pair(nullptr, nullptr); } static node_t *insert(node_t *t, int k, node_t *new_t) { auto s = split(t, k); return merge(merge(s.first, new_t), s.second); } static std::pair erase(node_t *t, int k) { auto sr = split(t, k + 1); auto sl = split(sr.first, k); return std::make_pair(merge(sl.first, sr.second), sl.second); } static node_t *find(node_t *t, int k) { assert(t != nullptr); int c = count(t->lch); if (k == c) return t; if (k < c) return find(t->lch, k); return find(t->rch, k - c - 1); } static void traverse(node_t *t, const std::function &func) { if (!t) return; if (t->lch) traverse(t->lch, func); if (t->rch) traverse(t->rch, func); func(t); return; } }; static int seed = 28313234; // seed はテキトー。デバッグしやすいように固定。 template struct Treap { typedef node_t node; std::function dice_; public: node * root_; Treap() : root_(nullptr) { dice_ = std::bind(std::uniform_real_distribution(0.000,1.000), std::mt19937(seed)); } ~Treap() {} void insert(int k, T val) { root_ = node::insert(root_, k, new node(val, dice_())); } // value based int upper_bound(T val) { std::function F = [&](node *s, int left)->int { assert(s != nullptr); if (val < s->val) { if (!s->lch) return left; else return F(s->lch, left); } else { int c = node::count(s->lch); if (!s->rch) return (left + (c + 1)); else return F(s->rch, left + c + 1); } }; if (!root_) return 0; return F(root_, 0); } void insert(T val) { insert(upper_bound(val), val); } void erase(int k) { node *p; std::tie(root_, p) = node::erase(root_, k); p->lch = p->rch = nullptr; delete p; } T find(int k) { if (!(0 <= k && k < node::count(root_)))return -1; node *p = node::find(root_, k); return p->val; } // shift for [l,r) 区間ないの要素を一つずらす。 void shift(int l, int r) { if (l == r - 1) return; assert(llazy = true; lr->lazy_val = val; root_ = node::merge(node::merge(sl.first, lr), sr.second); } // min at [l,r) T Min(int l, int r) { assert(lval; root_ = node::merge(node::merge(sl.first, lr), sr.second); return val; } T get(int k) { if (0 <= k && k < size()) return at(k); return 0; } void set(int k, T val) { auto sr = node::split(root_, k + 1); auto sl = node::split(sr.first, k); auto lr = sl.second; assert(lr != nullptr); lr->val = val; root_ = node::merge(node::merge(sl.first, lr), sr.second); } void _dump(node *t, std::string tab) { if (!t) return; std::cerr << tab << " " << t->val << " " << t->cnt << std::endl; if (t->lch) { _dump(t->lch, tab + "L"); } if (t->rch) { _dump(t->rch, tab + "R"); } } void dump() { std::cerr << "*******" << std::endl; _dump(root_, ""); std::cerr << std::endl; } }; Treaptr; int main() { cin >> n >> m; rep(i, n) { LL x, y; cin >> x; if (x == 1) { cin >> y; tr.insert(y); } else { ans = tr.find(m - 1); cout <