标签:spl strong second || air code i++ size lan
咕咕。
#include <bits/stdc++.h>
using namespace std;
//Start
typedef long long ll;
typedef double db;
#define mp(a,b) make_pair(a,b)
#define x(a) a.first
#define y(a) a.second
#define b(a) a.begin()
#define e(a) a.end()
#define sz(a) int((a).size())
#define pb(a) push_back(a)
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
//Data
const int N=1e5;
//Fhqtreap
int top,cnt,ch[N+7][2],v[N+7],p[N+7],sz[N+7];
int low(int x){return sz[x]=1+sz[ch[x][0]]+sz[ch[x][1]];}
int wen(int x){return sz[++cnt]=1,v[cnt]=x,p[cnt]=rand(),cnt;}
int merge(int x,int y){
if(!x||!y) return x^y;
if(p[x]<p[y]) return ch[x][1]=merge(ch[x][1],y),low(x),x;
return ch[y][0]=merge(x,ch[y][0]),low(y),y;
}
int split(int rt,int k,int&x,int&y){
if(!rt) return x=y=0;
if(v[rt]<=k) return x=rt,split(ch[rt][1],k,ch[rt][1],y),low(rt),0;
return y=rt,split(ch[rt][0],k,x,ch[rt][0]),low(rt),0;
}
int kth(int x,int k){
for(;k!=sz[ch[x][0]]+1;)
if(k<=sz[ch[x][0]]) x=ch[x][0];
else k-=sz[ch[x][0]]+1,x=ch[x][1];
return x;
}
//Main
int main(){
int n; scanf("%d",&n);
for(int i=1;i<=n;i++){
int o,a,x,y,z; scanf("%d%d",&o,&a);
if(o==1) split(top,a,x,y),top=merge(merge(x,wen(a)),y);
else if(o==2) split(top,a,x,z),split(x,a-1,x,y),
y=merge(ch[y][0],ch[y][1]),top=merge(merge(x,y),z);
else if(o==3) split(top,a-1,x,y),printf("%d\n",sz[x]+1),top=merge(x,y);
else if(o==4) printf("%d\n",v[kth(top,a)]);
else if(o==5) split(top,a-1,x,y),printf("%d\n",v[kth(x,sz[x])]),top=merge(x,y);
else if(o==6) split(top,a,x,y),printf("%d\n",v[kth(y,1)]),top=merge(x,y);
}
return 0;
}
标签:spl strong second || air code i++ size lan
原文地址:https://www.cnblogs.com/Wendigo/p/12883106.html