#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define forr(x,arr) for(auto&& x:arr) #define _overload3(_1,_2,_3,name,...) name #define _rep2(i,n) _rep3(i,0,n) #define _rep3(i,a,b) for(int i=int(a);i=int(a);i--) #define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__) #define all(x) (x).begin(),(x).end() #define bit(n) (1LL<<(n)) #define sz(x) ((int)(x).size()) #define TEN(n) ((ll)(1e##n)) #define fst first #define snd second string DBG_DLM(int &i){return(i++==0?"":", ");} #define DBG_B(exp){int i=0;os<<"{";{exp;}os<<"}";return os;} templateostream&operator<<(ostream&os,vectorv); templateostream&operator<<(ostream&os,setv); templateostream&operator<<(ostream&os,queueq); templateostream&operator<<(ostream&os,priority_queueq); templateostream&operator<<(ostream&os,pairp); templateostream&operator<<(ostream&os,mapmp); templateostream&operator<<(ostream&os,unordered_mapmp); templatevoid DBG(ostream&os,TPL t){} templatevoid DBG(ostream&os,TPL t){os<<(I==0?"":", ")<(t);DBG(os,t);} templatevoid DBG(ostream&os,pairp,string delim){os<<"("<ostream&operator<<(ostream&os,tuplet){os<<"(";DBG<0,tuple,Ts...>(os,t);os<<")";return os;} templateostream&operator<<(ostream&os,pairp){DBG(os,p,", ");return os;} templateostream&operator<<(ostream&os,vectorv){DBG_B(forr(t,v){os<ostream&operator<<(ostream&os,sets){DBG_B(forr(t,s){os<ostream&operator<<(ostream&os,queueq){DBG_B(for(;q.size();q.pop()){os<ostream&operator<<(ostream&os,priority_queueq){DBG_B(for(;q.size();q.pop()){os<ostream&operator<<(ostream&os,mapm){DBG_B(forr(p,m){os<");});} templateostream&operator<<(ostream&os,unordered_mapm){DBG_B(forr(p,m){os<");});} #define DBG_OVERLOAD(_1,_2,_3,_4,_5,_6,macro_name,...)macro_name #define DBG_LINE(){char s[99];sprintf(s,"line:%3d | ",__LINE__);cerr<;using pll=pair;using pil=pair;using pli=pair; using vs=vector;using vvs=vector;using vvvs=vector; using vb=vector;using vvb=vector;using vvvb=vector; using vi=vector;using vvi=vector;using vvvi=vector; using vl=vector;using vvl=vector;using vvvl=vector; using vd=vector;using vvd=vector;using vvvd=vector; using vpii=vector;using vvpii=vector;using vvvpii=vector; templatebool amax(A&a,const B&b){return b>a?a=b,1:0;} templatebool amin(A&a,const B&b){return b>l;return l;} string rs(){string s;cin>>s;return s;} template struct Treap { struct Node { static Val comp(const Val& l, const Val& r) { return min(l, r); }; Val v; int priority; Node *lef, *rig; int size_; Val summary; Node() {} Node(Val v) : v(v), priority(xor128()), lef(nullptr), rig(nullptr), size_(1), summary(v) {} void *operator new(std::size_t) { static Node pool[500010]; static int p = 0; return pool + p++; } int size() const { return size_;} string to_string() const { string res; to_string(res); return res; } void to_string(string &res) const { res += "Node [v="; res += std::to_string(v); res += ", size="; res += std::to_string(size_); res += "]"; } static int xor128() { static random_device rnd; static int x = 123456789, y = 362436069, z = 521288629, w = rnd(); int t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); return w; } static void to_string(const Node* a, string &res, int indent) { if (a == nullptr) return; to_string(a->lef, res, indent + 2); for (int i = 0; i < indent; i++) res += ' '; a->to_string(res); res += '\n'; to_string(a->rig, res, indent + 2); } static Node* update(Node* a) { if (a == nullptr) return nullptr; a->size_ = 1 + size(a->lef) + size(a->rig); a->summary = a->v; if (a->lef != nullptr) a->summary = comp(a->summary, a->lef->summary); if (a->rig != nullptr) a->summary = comp(a->summary, a->rig->summary); return a; } static int size(const Node* x) { return x == nullptr ? 0 : x->size_; } static vector nodes(Node* a) { vector ret(size(a)); nodes(a, ret, 0, size(a)); return ret; } static void nodes(Node* a, vector &ns, int L, int R) { if (a == nullptr) return; nodes(a->lef, ns, L, L + size(a->lef)); ns[L + size(a->lef)] = a; nodes(a->rig, ns, R - size(a->rig), R); } static Node* merge(Node* a, Node* b) { if (b == nullptr) return a; if (a == nullptr) return b; if (a->priority > b->priority) { a->rig = merge(a->rig, b); return update(a); } else { b->lef = merge(a, b->lef); return update(b); } } static pair split(Node* a, int k) { if (a == nullptr) return make_pair(nullptr, nullptr); if (k <= size(a->lef)) { auto s = split(a->lef, k); a->lef = s.second; s.second = update(a); return s; } else { auto s = split(a->rig, k - size(a->lef) - 1); a->rig = s.first; s.first = update(a); return s; } } }; using node = Node; using np = node*; static np merge_technically(np a, np b) { if (node::size(a) > node::size(b)) swap(a, b); for (np cur : node::nodes(a)) { cur->lef = cur->rig = nullptr; b = insert_b(b, cur); } return b; } static pair split_less(np a, Val v) { if (a == nullptr) return make_pair(nullptr, nullptr); if (a->v < v) { auto s = split_less(a->rig, v); a->rig = s.first; s.first = node::update(a); return s; } else { auto s = split_less(a->lef, v); a->lef = s.second; s.second = node::update(a); return s; } } static pair split_leq(np a, Val v) { if (a == nullptr) return make_pair(nullptr, nullptr); if (a->v <= v) { auto s = split_leq(a->rig, v); a->rig = s.first; s.first = node::update(a); return s; } else { auto s = split_leq(a->lef, v); a->lef = s.second; s.second = node::update(a); return s; } } static np insert_k(np a, int k, const Val v) { auto lr = node::split(a, k); return node::merge(node::merge(lr.first, new node(v)), lr.second); } static np insert_b(np a, np v) { auto lr = split_less(a, v->v); return node::merge(node::merge(lr.first, v), lr.second); } static np erase_k(np a, int k) { auto lr = node::split(a, k); auto mr = node::split(lr.second, 1); return node::merge(lr.first, mr.second); } static np erase_b(np a, Val v) { auto lr = split_less(a, v); auto mr = node::split(lr.second, 1); return node::merge(lr.first, mr.second); } static np get_k(np a, int k) { while (a != nullptr) { if (k < node::size(a->lef)) { a = a->lef; } else if (k == node::size(a->lef)) { break; } else { k = k - node::size(a->lef) - 1; a = a->rig; } } return a; } public: np root; Treap() : root(nullptr) {} Treap(np root) : root(root) {} Treap(Treap l, Treap r) : root(node::merge(l.root, r.root)) {} string to_string() const { string res; node::to_string(root, res, 0); return res; } int size() const { return node::size(root); } pair split_k(int k) { auto lr = node::split(root, k); return make_pair(Treap(lr.first), Treap(lr.second)); } void insert_k(const Val val, int k) { root = insert_k(root, k, val); } void erase_k(int k) { root = erase_k(root, k); } Val operator[](int k) const { assert(size() > k); return get_k(root, k)->v; } void insert_b(const Val val) { root = insert_b(root, new node(val)); } void erase_b(const Val val) { if (contains_b(val)) root = erase_b(root, val); } int count_less_b(const Val q) const { auto a = root; int lsize = 0; while (a != nullptr) { if (a->v < q) { lsize += node::size(a->lef) + 1; a = a->rig; } else { a = a->lef; } } return lsize; } int count_leq_b(const Val q) const { auto a = root; int lsize = 0; while (a != nullptr) { if (a->v <= q) { lsize += node::size(a->lef) + 1; a = a->rig; } else { a = a->lef; } } return lsize; } int count_b(const Val q) const { return count_leq_b(q) - count_less_b(q); } bool contains_b(const Val q) const { auto a = root; while (a != nullptr) { if (a->v == q) return true; else if (a->v < q) a = a->rig; else a = a->lef; } return false; } pair split_less_b(const Val v) { auto lr = split_less(root, v); return make_pair(Treap(lr.first), Treap(lr.second)); } pair split_leq_b(const Val v) { auto lr = split_leq(root, v); return make_pair(Treap(lr.first), Treap(lr.second)); } }; template ostream& operator<<(ostream& os, const Treap& treap) { vi tp; rep(i, sz(treap)) tp.emplace_back(treap[i]); os << tp; return os; } void Main() { int Q = ri(); vl A; ll sum = 0; using TP = Treap; TP tp; rep(i, Q) { ll t = ri(), x = ri(); out(t, x); if (t == 1) { ll p = x - sum; A.emplace_back(p); tp.insert_b(p); } else if (t == 2) { ll p = A[x-1]; tp.erase_b(p); } else if (t == 3) { sum += x; } else { assert(false); } out(sum, tp); auto check = [&](ll x) -> bool { ll p = x - sum; return sz(tp) - tp.count_less_b(p) >= x; }; ll ok = 0; ll ng = Q+1; while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; bool c = check(mid); if (c) ok = mid; else ng = mid; } cout << ok << '\n'; } } signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }