#include using namespace std; #if __has_include() #include using namespace atcoder; templateistream &operator>>(istream &is,static_modint &a){long long b;is>>b;a=b;return is;} istream &operator>>(istream &is,modint &a){long long b;cin>>b;a=b;return is;} #endif using ll=long long; using ull=unsigned long long; using P=pair; templateusing minque=priority_queue,greater>; templatebool chmax(T &a,const T &b){return (abool chmin(T &a,const T &b){return (a>b?(a=b,true):false);} templateistream &operator>>(istream &is,pair&p){is>>p.first>>p.second;return is;} templateistream &operator>>(istream &is,vector &a){for(auto &i:a)is>>i;return is;} templatevoid operator++(pair&a,int n){a.first++,a.second++;} templatevoid operator--(pair&a,int n){a.first--,a.second--;} templatevoid operator++(vector&a,int n){for(auto &i:a)i++;} templatevoid operator--(vector&a,int n){for(auto &i:a)i--;} #define reps(i,a,n) for(int i=(a);i<(n);i++) #define rep(i,n) reps(i,0,n) #define all(x) x.begin(),x.end() #define pcnt(x) __builtin_popcount(x) ll myceil(ll a,ll b){return (a+b-1)/b;} template auto vec(const int (&d)[n],const T &init=T()){ if constexpr (id(d,init)); else return init; } #ifdef LOCAL #include "debug.h" #else #define debug(...) static_cast(0) templateostream &operator<<(ostream &os,const pair&p){os<>testcase; for(int i=0;i struct splay_tree{ struct node{ node *par,*left,*right; int sz; S val,sum; node():par(nullptr),left(nullptr),right(nullptr),sz(1),val(e()),sum(e()){} void set(S v){ this->val=v; this->sum=v; if(this->left)this->sum=op(this->left->sum,this->sum); if(this->right)this->sum=op(this->sum,this->right->sum); } void rotate(){ node *pp,*p,*c; p=this->par; pp=p->par; if(p->left==this){ c=this->right; this->right=p; p->left=c; } else{ c=this->left; this->left=p; p->right=c; } if(pp&&pp->left==p)pp->left=this; if(pp&&pp->right==p)pp->right=this; this->par=pp; p->par=this; if(c)c->par=p; p->update(); this->update(); } int state()const{ if(!this->par)return 0; if(this->par->left==this)return 1; if(this->par->right==this)return -1; return 0; } void splay(){ while(this->state()){ if(this->par->state()==0)this->rotate(); else if(this->state()==this->par->state()){ this->par->rotate(); this->rotate(); } else{ this->rotate(); this->rotate(); } } } void update(){ this->sz=1; this->sum=this->val; if(this->left){ this->sz+=this->left->sz; this->sum=op(this->left->sum,this->sum); } if(this->right){ this->sz+=this->right->sz; this->sum=op(this->sum,this->right->sum); } } }; private: node *root=nullptr; node *get(int id,node *root){ node *now=root; while(true){ int lsize=now->left?now->left->sz:0; if(idleft; else if(id==lsize){ now->splay(); return now; } else{ now=now->right; id-=lsize+1; } } } node *merge(node *lroot,node *rroot){ if(!lroot)return rroot; if(!rroot)return lroot; lroot=get(lroot->sz-1,lroot); lroot->right=rroot; rroot->par=lroot; lroot->update(); return lroot; } pairsplit(int lcnt,node *root){ if(lcnt==0)return {nullptr,root}; if(lcnt==root->sz)return {root,nullptr}; root=get(lcnt,root); node *lroot,*rroot; lroot=root->left; rroot=root; lroot->par=nullptr; rroot->left=nullptr; rroot->update(); return {lroot,rroot}; } node *insert(int id,node *nd,node *root){ auto spl=split(id,root); return merge(merge(spl.first,nd),spl.second); } node *erase(int id,node *root){ root=get(id,root); node *lroot=root->left; node *rroot=root->right; if(lroot)lroot->par=nullptr; if(rroot)rroot->par=nullptr; delete(root); return merge(lroot,rroot); } node *between(int l,int r){ if(l==0&&r==this->root->sz)return this->root; if(l==0){ root=get(r,root); return root->left; } if(r==this->root->sz){ root=get(l-1,root); return root->right; } node *rht=get(r,root); node *lft=rht->left; lft->par=nullptr; root=lft; lft=get(l-1,lft); root=rht; rht->left=lft; lft->par=rht; rht->update(); return lft->right; } public: const S &operator[](int id){ root=get(id,root); return root->val; } void insert(S x){ node *nd=new node(); nd->set(x); if(!root){ root=insert(0,nd,root); return; } node *now=root; while(true){ if(now->val==x){ now->splay(); root=now; int lsize=root->left?root->left->sz:0; root=insert(lsize,nd,root); return; } else if(now->val>x){ if(!now->left){ now->left=nd; nd->par=now; nd->splay(); root=nd; return; } else now=now->left; } else{ if(!now->right){ now->right=nd; nd->par=now; nd->splay(); root=nd; return; } else now=now->right; } } } void erase(S x){ if(!root)return; node *now=root; while(true){ if(now->val==x){ now->splay(); root=now; int lsize=now->left?now->left->sz:0; root=erase(lsize,root); return; } else if(now->val>x){ if(!now->left)return; else now=now->left; } else{ if(!now->right)return; else now=now->right; } } } int size()const{return root?root->sz:0;} S prod(int l,int r){ if(l==r)return e(); node *pr=between(l,r); return pr->sum; } };//バグってるかも ll op(ll a,ll b){return 0;} ll e(){return 0;} void SOLVE(){ int q,k; cin>>q>>k; splay_trees; while(q--){ int t; cin>>t; if(t==1){ ll x; cin>>x; s.insert(x); } else{ if(s.size()