社区讨论
93分求助,改不动了QAQ
P3377【模板】可并堆 1参与者 4已保存回复 3
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @lobqv3kw
- 此快照首次捕获于
- 2023/10/30 01:27 2 年前
- 此快照最后确认于
- 2023/11/04 06:02 2 年前
CPP
//配对堆
#include<bits/stdc++.h>
#define nul NULL
using namespace std;
const int M=100010;
struct node{
int val;
bool del;
node*bro,*son,*fa;
node(){
bro=son=nul;
del=false;
fa=this;
}
}heap[M];
node*merge(node*x,node*y){
if(x==nul)return y;
if(y==nul)return x;
if(x->val>y->val)swap(x,y);
y->bro=x->son;
x->son=y;
return x;
}
node*merges(node*x){
if(x==nul||x->bro==nul)return x;
return merge(merge(x,x->bro),merges(x->bro->bro));
}
node*find(node*x){
return x->fa==x?x:x->fa=find(x->fa);
}
int n,m;
void init(){
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>heap[i].val;
}
}
int main(){
// freopen("C:\\in.txt","r",stdin);
init();
for(;m;m--){
int mode;
cin>>mode;
if(mode-1){
int id;
cin>>id;
if(heap[id].del){
cout<<-1<<endl;
continue;
}
node*root=find(&heap[id]);
cout<<root->val<<endl;
root->del=true;
root->fa=merges(root->son);
if(root->fa!=nul)root->fa->fa=root->fa;
}
else{
int a,b;
cin>>a>>b;
if(heap[a].del||heap[b].del||heap[a].fa==heap[b].fa)continue;
node*x=find(&heap[a]);
node*y=find(&heap[b]);
x->fa=y->fa=merge(x,y);
}
}
return 0;
}
wa了第11个点qwq
回复
共 3 条回复,欢迎继续交流。
正在加载回复...