分析:
好吧,其实没什么好分析的,左偏树裸题。
Code:
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<algorithm>
using namespace std;
const int N=1e6+;
int n,m;
struct Node{
int ls,rs,val;
int dist,fa;
}t[N];
inline int merge(int x,int y)
{
if(!x||!y)return x+y;
if(t[x].val>t[y].val||(t[x].val==t[y].val&&x>y))
swap(x,y);
int &ur=t[x].rs,&ul=t[x].ls;
ur=merge(ur,y);
t[ur].fa=x;
if(t[ur].dist>t[ul].dist)swap(ur,ul);
t[x].dist=t[ur].dist+;
return x;
}
inline void delet(int x)
{
int ur=t[x].rs,ul=t[x].ls;
t[x].val=;t[ur].fa=,t[ul].fa=;
merge(ur,ul);
}
inline int find(int x)
{return t[x].fa?find(t[x].fa):x;}
int main()
{
ios::sync_with_stdio(false);
cin>>n;t[].dist=-;
for(int i=;i<=n;i++)
cin>>t[i].val;
cin>>m;
char opt;
int x,y;
for(int i=;i<=m;i++){
cin>>opt;
if(opt=='M'){
cin>>x>>y;
if(t[x].val*t[y].val==)continue;
x=find(x),y=find(y);
if(x!=y)
merge(x,y);
}
else{
cin>>x;
if(t[x].val==)cout<<<<endl;
else{
x=find(x);
cout<<t[x].val<<endl;
delet(x);}
}
}
return ;
}