FHQtreap(我有个绝妙的理解方法,但课的时间不够[doge])
阅读原文时间:2023年07月08日阅读:3

FHQtreap板子(P1486 [NOI2004] 郁闷的出纳员

会了FHQ,treap什么的就忘了吧……

#include
using namespace std;
struct FHQ
{
int v,w,size,l,r;
}t[300005];
int root,k,n,_min,tot,add,x,y,ans,cnt;
char ch;
int newnode(int k)
{
++tot;
if(!root)root=1;
t[tot].size=1,t[tot].v=k,t[tot].w=rand();
return tot;
}
void update(int now)
{
t[now].size=t[t[now].l].size+t[t[now].r].size+1;
}
int merge(int x,int y)
{
if(!x||!y)return x+y;
if(t[x].wk-1)return find(t[now].l,k);
if(t[t[now].l].size>n>>_min;
for(int i=1;i<=n;i++) { cin>>ch;
if(ch=='I')
{
cin>>k;
if(k<_min)continue; split(root,k,x,y); root=merge(merge(x,newnode(k)),y); } if(ch=='A') { cin>>k;
change(root,k);
}
if(ch=='S')
{
cin>>k;
change(root,-k);
split(root,_min,x,y);
ans+=t[x].size;
root=y;
}
if(ch=='F')
{
cin>>k;
if(t[root].size<k)
{
cout<<-1<<endl;
continue;
}
cout<<t[find(root,tot-ans-k+1)].v<<endl;
}
///pp();
}
cout<<ans;
return 0;
}