#include #include #include #include #include using namespace __gnu_pbds; using namespace std; template using Set = tree, rb_tree_tag, tree_order_statistics_node_update>; int main() { int q; cin >> q; Set> st; vector> tmp; long long u = 0; for (int i = 0; i < q; i++) { int t; long long x; cin >> t >> x; if (t == 1) { int j = tmp.size(); tmp.emplace_back(x - u, j); st.insert(make_pair(x - u, j)); } else if (t == 2) { st.erase(tmp[x - 1]); } else { u += x; } long long ok = 0; long long ng = 2e5; while (ng - ok > 1) { int mid = (ok + ng) / 2; int cnt = st.size() - st.order_of_key(make_pair(mid - u, 0)); if (cnt >= mid) { ok = mid; } else { ng = mid; } } cout << ok << endl; } }