#include #include #include #include #include #include #include using namespace std; struct BIT { BIT(int n) : b(n + 1), n(n) {} void add(int i, int v) { for (int k = i + 1; k <= n; k += k & -k) b[k] += v; } int sum(int k) { int s = 0; for (; k > 0; k -= k & -k) s += b[k]; return s; } int lower_bound(int s) { if (s <= 0) return 0; int x = 0, w = 1; while (w << 1 <= n) w <<= 1; do { int k = x + w; if (k <= n && b[k] < s) { s -= b[k]; x += w; } } while (w >>= 1); return x + 1; } vector b; int n; }; using I = int; template I lower_bound(I i0, I i1, F f) { while (i0 < i1) { I i = (i0 + i1) / 2; if (f(i)) i1 = i; else i0 = i + 1; } return i0; } int main() { ios::sync_with_stdio(false); cin.tie(0); int q; cin >> q; vector t(q), x(q); for (int i = 0; i < q; i++) { cin >> t[i] >> x[i]; } vector> a; int64_t d = 0; for (int i = 0; i < q; i++) { if (t[i] == 1) a.push_back(pair(x[i] - d, i)); if (t[i] == 2) x[i] = a[x[i] - 1].second; if (t[i] == 3) d += x[i]; } int n = a.size(); sort(a.begin(), a.end()); vector p(q, -1); for (int j = 0; j < n; j++) { p[a[j].second] = j; } BIT bt(n); d = 0; int m = 0; for (int i = 0; i < q; i++) { if (t[i] == 1) { bt.add(p[i], 1); m++; } else if (t[i] == 2) { bt.add(p[x[i]], -1); m--; } else { d += x[i]; } I j = lower_bound(0, n, [&](I j) { return m - bt.sum(j) <= a[j].first + d; }); cout << m - bt.sum(j) << '\n'; } return 0; }