#include "bits/stdc++.h" using namespace std; #define DEBUG(x) cout<<#x<<": "< #define vl vector #define vii vector< vector > #define vll vector< vector > #define vs vector #define pii pair #define pll pair #define pis pair #define psi pair const int inf = 1000000001; const ll INF = 1e18 * 2; #define MOD 1000000007 #define mod 1000000009 #define pi 3.14159265358979323846 #define Sp(p) cout< > lab; lab.push_back(vector()); vl add; int num = 0; //DEBUG(block) for (int unko = 0; unko < q; unko++) { int t, x; scanf("%d%d", &t, &x); if (t == 1) { lab[num / block].push_back(pll(x, num)); if (lab[num / block].size() == block) { lab.push_back(vector()); add.push_back(0); } sort(lab[num / block].begin(), lab[num / block].end()); num++; } else if (t == 2) { x--; i = x / block; for (j = 0; j < lab[i].size(); j++) { if (lab[i][j].second == x) { lab[i][j].first += none; break; } } sort(lab[i].begin(), lab[i].end()); } else { for (i = 0; i < add.size(); i++) { add[i] += x; } for (j = 0; j < lab[lab.size() - 1].size(); j++) { lab[lab.size() - 1][j].first += x; } } ll left = 0, right = 100001; while (left + 1 < right) { ll mid = (left + right) / 2; int cnt = 0; for (i = 0; i < add.size(); i++) { int idx = lower_bound(lab[i].begin(), lab[i].end(), pll(mid - add[i], -1)) - lab[i].begin(); cnt += block - idx; } int idx = lower_bound(lab[lab.size() - 1].begin(), lab[lab.size() - 1].end(), pll(mid, -1)) - lab[lab.size() - 1].begin(); cnt += lab[lab.size() - 1].size() - idx; if (cnt >= mid) { left = mid; } else { right = mid; } } cout << left << endl; /* for (i = 0; i < lab.size(); i++) { for (j = 0; j < lab[i].size(); j++) { printf("(%lld, %lld) ", lab[i][j].first, lab[i][j].second); } cout << endl; } */ } } /* 5 1 1 1 2 1 3 1 4 1 5 4 1 1 1 2 1 3 2 2 5 1 1 1 2 1 3 3 2 3 -10 10 1 396579765 1 798135558 1 901129114 3 -929424919 2 3 1 -643609488 3 697031258 3 -245746533 1 -804449362 2 2 */