#include #include #include #include #include #include #include #include #include #include #include #define mk make_pair #define pb push_back #define printf printf_s #define scanf scanf_s using namespace std; typedef long long int ll; typedef pair pos; const ll MOD = 1000000007, N = 100001, dx[4] = { -1,1,0,0 }, dy[4] = { 0,0,-1,1 }, MIN = -72340172838, MAX = 72340172838; ll mn(ll a, ll b) { if (a == -1)return b; if (b == -1)return a; return min(a, b); } ll gcd(ll v1, ll v2) { if (v1 == 0)return v2; if (v2 == 0)return v1; if (v2 > v1)return gcd(v2%v1, v1); return gcd(v1%v2, v2); } ll pw(ll v1, ll v2) { ll v3 = 1; while (v2 > 0) { if (v2 % 2)v3 = (v3*v1) % MOD; v1 = (v1*v1) % MOD; v2 /= 2; } return v3; } struct ab { ll a, b; bool operator<(const ab& right) const { return right.b*a - right.a*b < 0; } }; ll Q,xl[N],ti=1,bt[N]; pos tx[N]; void sxl() { ll xl2[N],ti2=ti; for (int i1 = 1, i2 = 1; i1 < ti; i1++) { if (i1 != 1 && xl[i1] == xl[i1 - 1]) { ti2--; } else { xl2[i2] = xl[i1]; i2++; } } memset(xl, 0, sizeof(xl)); for (int i = 1; i < ti2; i++)xl[i] = xl2[i]; ti = ti2; } void ad(ll v1, ll v2) { while (v1 <= ti - 1) { bt[v1] += v2; v1 += v1 & -v1; } } ll sm(ll v1) { ll v2 = 0; while (v1 > 0) { v2 += bt[v1]; v1 -= v1 & -v1; } return v2; } bool ok(ll tt,ll mdv,ll tot) { ll v1 = sm(lower_bound(xl + 1, xl + ti, mdv-tt) - xl - 1); return (tot - v1) >= mdv; } void src(ll tt,ll tot) { ll mnv = 0, mxv = 1000000001; while (mxv - mnv > 1) { ll md = (mxv + mnv) / 2; if (ok(tt,md,tot))mnv = md; else mxv = md; } cout << mnv << endl; } int main() { cin >> Q; for (ll i = 0, tt = 0; i < Q; i++) { cin >> tx[i].first >> tx[i].second; if (tx[i].first == 3)tt += tx[i].second; if (tx[i].first == 1) { xl[ti] = tx[i].second - tt; ti++; } } sort(xl + 1, xl + ti); sxl(); vector rsc; for (ll i = 0,tt=0,tot=0; i < Q; i++) { if (tx[i].first == 1) { ll id1 = find(xl + 1, xl + ti, tx[i].second - tt) - xl; ad(id1, 1); rsc.push_back(tx[i].second - tt); tot++; } if (tx[i].first == 2) { ad(find(xl + 1, xl + ti, rsc[tx[i].second - 1]) - xl, -1); tot--; } if (tx[i].first == 3)tt += tx[i].second; src(tt,tot); } return 0; }