#include #include using namespace __gnu_pbds; using namespace std; typedef long long int ll; typedef pair P; typedef pair Pll; typedef vector Vi; //typedef tuple T; #define FOR(i,s,x) for(int i=s;i<(int)(x);i++) #define REP(i,x) FOR(i,0,x) #define ALL(c) c.begin(), c.end() #define DUMP( x ) cerr << #x << " = " << ( x ) << endl template using indexed_set = tree, rb_tree_tag, tree_order_statistics_node_update>; const int dr[4] = {-1, 0, 1, 0}; const int dc[4] = {0, 1, 0, -1}; const ll INF = 1e18; int main() { int Q; scanf("%d", &Q); vector> events; REP(_, Q) { int t; ll x; scanf("%d %lld", &t, &x); events.emplace_back(t, x); } vector up_events(Q + 1, 0); REP(i, Q) { int t; ll x; tie(t, x) = events[i]; if (t == 3) up_events[i + 1] = x; up_events[i + 1] += up_events[i]; } vector> final_powers; REP(i, Q) { int t; ll x; tie(t, x) = events[i]; if (t == 1) { ll final_power = x + up_events[Q] - up_events[i]; final_powers.emplace_back(final_power, i); } } sort(ALL(final_powers)); int N = final_powers.size(); vector idx2tree(Q, -1); REP(i, N) { ll x; int idx; tie(x, idx) = final_powers[i]; idx2tree[idx] = i; } vector labo_members; indexed_set idxset; int prev = 0; REP(q, Q) { int t; ll x; tie(t, x) = events[q]; if (t == 1) { idxset.insert(idx2tree[q]); labo_members.emplace_back(q); } else if (t == 2) { x--; idxset.erase(idx2tree[labo_members[(int)x]]); } int num_members = idxset.size(); int left = 0, right = num_members + 1; while (left + 1 < right) { int mid = (left + right) >> 1; int idx = *idxset.find_by_order(num_members - mid); ll orig = final_powers[idx].second; ll now_power = events[orig].second + up_events[q + 1] - up_events[orig]; (now_power >= mid ? left : right) = mid; } printf("%d\n", left); prev = left; } return 0; }