#include #include #include const int INF = 0; // 最小値として機能する値 template struct SegTree { int n; std::vector dat; T identity; SegTree(int n_, T id) : identity(id) { n = 1; while (n < n_) n *= 2; dat.assign(2 * n - 1, identity); } void update(int k, T a) { k += n - 1; dat[k] = a; while (k > 0) { k = (k - 1) / 2; dat[k] = std::max(dat[k * 2 + 1], dat[k * 2 + 2]); } } // [a, b) の最大値を求める T query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return identity; if (a <= l && r <= b) return dat[k]; T vl = query(a, b, k * 2 + 1, l, (l + r) / 2); T vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return std::max(vl, vr); } T query(int a, int b) { return query(a, b, 0, 0, n); } }; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int Q; std::cin >> Q; SegTree seg(Q, INF); int count = 0; for (int i = 0; i < Q; ++i) { int type; std::cin >> type; if (type == 1) { int x; std::cin >> x; seg.update(count, x); count++; } else { int k; std::cin >> k; std::cout << seg.query(count - k, count) << "\n"; } } return 0; }