题目大意:给定n个点,每一个点有一个权值,提供两种操作:

1.将两个点所在集合合并

2.将一个点所在集合的最小的点删除并输出权值

非常裸的可并堆 n<=100W 启示式合并不用想了

左偏树就是快啊~

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define M 1001001
using namespace std;
struct abcd{
abcd *ls,*rs;
int h,pos,score;
abcd(int x,int y);
}*null=new abcd(0,0x3f3f3f3f),*tree[M];
abcd :: abcd(int x,int y)
{
ls=rs=null;
if(!null) h=-1;
else h=0;
pos=x;score=y;
}
abcd* Merge(abcd *x,abcd *y)
{
if(x==null) return y;
if(y==null) return x;
if(x->score>y->score)
swap(x,y);
x->rs=Merge(x->rs,y);
if(x->ls->h<x->rs->h)
swap(x->ls,x->rs);
x->h=x->rs->h+1;
return x;
}
int n,m;
int fa[M];
bool dead[M];
int Find(int x)
{
if(!fa[x]||fa[x]==x)
return fa[x]=x;
return fa[x]=Find(fa[x]);
}
void Unite(int x,int y)
{
x=Find(x);y=Find(y);
if(x==y) return ;
fa[x]=y;
tree[y]=Merge(tree[x],tree[y]);
}
int main()
{ //freopen("1455.in","r",stdin);
//freopen("1455.out","w",stdout); int i,x,y;
char p[10];
cin>>n;
for(i=1;i<=n;i++)
scanf("%d",&x),tree[i]=new abcd(i,x);
cin>>m;
for(i=1;i<=m;i++)
{
scanf("%s",p);
if(p[0]=='M')
{
scanf("%d%d",&x,&y);
if(dead[x]||dead[y])
continue;
Unite(x,y);
}
else
{
scanf("%d",&x);
if(dead[x])
{
puts("0");
continue;
}
x=Find(x);
printf("%d\n",tree[x]->score);
dead[tree[x]->pos]=1;
tree[x]=Merge(tree[x]->ls,tree[x]->rs);
}
}
}

BZOJ 1455 罗马游戏 左偏树的更多相关文章

  1. bzoj 1455: 罗马游戏 左偏树+并查集

    1455: 罗马游戏 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 668  Solved: 247[Submit][Status] Descriptio ...

  2. BZOJ 1455 罗马游戏 ——左偏树

    [题目分析] 左偏树的模板题目,大概就是尽量维护树的深度保持平衡,以及尽可能的快速合并的一种堆. 感觉和启发式合并基本相同. 其实并没有快很多. 本人的左偏树代码自带大常数,借鉴请慎重 [代码] #i ...

  3. 1455: 罗马游戏[左偏树or可并堆]

    1455: 罗马游戏 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1861  Solved: 798[Submit][Status][Discuss] ...

  4. BZOJ1455 罗马游戏 左偏树 可并堆

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1455 题意概括 n个人,2种操作. 一种是合并两个人团,一种是杀死某一个人团的最弱的人. 题解 左 ...

  5. [BZOJ1455]罗马游戏 左偏树+并查集

    1455: 罗马游戏 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 2285  Solved: 994[Submit][Status][Discuss] ...

  6. BZOJ 1455: 罗马游戏 [可并堆]

    1455: 罗马游戏 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1715  Solved: 718[Submit][Status][Discuss] ...

  7. bzoj 1455: 罗马游戏

    1455: 罗马游戏 Time Limit: 5 Sec  Memory Limit: 64 MB Description 罗马皇帝很喜欢玩杀人游戏. 他的军队里面有n个人,每个人都是一个独立的团.最 ...

  8. BZOJ 1455: 罗马游戏( 配对堆 + 并查集 )

    可并堆水题 --------------------------------------------------------- #include<bits/stdc++.h>   usin ...

  9. bzoj 4003: 城池攻占 左偏树

    题目大意 http://www.lydsy.com/JudgeOnline/problem.php?id=4003 题解 一开始看漏条件了 题目保证当占领城池可以使攻击力乘上\(v_i\)时,一定有\ ...

随机推荐

  1. 第11课 Git GUI程序的基本功能

    11-1 Git GUI程序的基本操作

  2. Labeling Balls(拓扑)

    http://poj.org/problem?id=3687 看题意看了半天没看懂怎么回事,看完Discuss彻底凌乱了..后来看了题解才懂,就是逆向建图+拓扑排序,建图时要判重边. #include ...

  3. codevs2596 售货员的难题(状压dp)

    2596 售货员的难题  时间限制: 1 s  空间限制: 32000 KB  题目等级 : 钻石 Diamond     题目描述 Description 某乡有n个村庄(1<n<=15 ...

  4. css3 文本模型

    我前期是一名前端开发者,经常会遇到关于文本模型的问题,很多地方我们会经常遇到这种问题.例如栏目的标题,在设计师给我们图的时候并不会考虑到标题的长度,所以我们自己开发的过程中自己注意这一点. 首先和大家 ...

  5. LeetCode刷题 1. Two Sum 两数之和 详解 C++语言实现 java语言实现

    1. Two Sum 两数之和 Given an array of integers, return indices of the two numbers such that they add up ...

  6. HDU 4474 Yet Another Multiple Problem BFS

    题意:求m的倍数中不包含一些数码的最小倍数数码是多少.比如15 ,不包含0  1 3,答案是45. BFS过程:用b[]记录可用的数码.设一棵树,树根为-1.树根的孩子是所有可用的数码,孩子的孩子也是 ...

  7. .Net Core 学习(二)上篇

    用Visual Studio和ASP.NET Core MVC创建Web API 1.启动Visual Studio.从文件菜单,选择新建>项目.选择ASP.NET Core Web Appli ...

  8. Android HTTP下载文件并保存到本地或SD卡

    想把文件保存到SD卡中,一定要知道SD卡的路径,获取SD卡路径: Environment.getExternalStorageDirectory() 另外,在保存之前要判断SD卡是否已经安装好,并且可 ...

  9. PHP CURL的几种用法

    1.抓取无访问控制文件 <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://localhost/mytest/ ...

  10. 转:Python结合P有winauto进行windows UI自动化

    https://blog.csdn.net/z_johnny/article/details/52778064