#include #include #include #include #include #include #include #include #include #include #include #define INF 1000000000ll #define MOD 1000000007ll #define EPS 1e-10 #define REP(i,m) for(long long i=0; i P; typedef long double ld; ll N = 100010; ll bit[100010]; void add(ll a, ll w) { for (ll x = a; x <= N; x += x & -x) bit[x] += w; } ll sum(ll a) { ll ret = 0; for (ll x = a; x > 0; x -= x & -x) ret += bit[x]; return ret; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll q; cin>>q; vector

t(q); vector pos; // 研究力の順位 REP(i,q) cin>>t[i].first>>t[i].second; vector

buf; ll crt=0; REP(i,q) { if(t[i].first==1) { buf.pb(P(t[i].second,crt)); crt++; } } pos.resize(crt); sort(ALL(buf)); REP(i,(ll)buf.size()) { pos[buf[i].second]=i; } crt=0; ll ofs=0; REP(i,q) { if(t[i].first==1) { add(pos[crt]+1,1); crt++; } if(t[i].first==2) { add(pos[t[i].second-1]+1,-1); } if(t[i].first==3) { ofs+=t[i].second; } ll lb=0,ub=INF; while(ub-lb>1) { ll mid=(ub+lb)/2; ll hoge=mid-ofs; auto ite=lower_bound(ALL(buf),P(hoge,-1)); ll foo=(ite-buf.begin()); ll num=sum(q); if(foo>0) num-=sum(foo); if(num>=mid) lb=mid; else ub=mid; } cout<