【题目大意】

给出一些数和一些操作。M:合并两个数所在的集合,如果有任意一个数被删除则忽略操作;K:删除某个数所在集合中最小的数。

【思路】

裸裸的,复习^ ^

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=+;
struct node
{
int key,dis,del;
int lson,rson,father;
}ltree[MAXN];
int n,m; int find(int a)
{
while (ltree[a].father!=a) a=ltree[a].father;
return a;
} void build(int rt,int val)
{
ltree[rt].key=val;
ltree[rt].dis=(rt==)?-:;
ltree[rt].del=;
ltree[rt].lson=ltree[rt].rson=;
ltree[rt].father=rt;
} int merge(int x,int y)
{
if (x==||y==) return (x|y);
if (ltree[x].key>ltree[y].key) swap(x,y);
ltree[x].rson=merge(ltree[x].rson,y);
int &l=ltree[x].lson,&r=ltree[x].rson;
ltree[l].father=ltree[r].father=x;
if (ltree[l].dis<ltree[r].dis) swap(l,r);
if (r==) ltree[x].dis=;
else ltree[x].dis=ltree[r].dis+;
return x;
} void Del(int rt)
{
int l=ltree[rt].lson,r=ltree[rt].rson;
ltree[l].father=l;
ltree[r].father=r;
ltree[rt].dis=ltree[rt].lson=ltree[rt].rson=;
ltree[rt].del=;
merge(l,r);
} void init()
{
scanf("%d",&n);
for (int i=;i<=n;i++)
{
int score;
scanf("%d",&score);
build(i,score);
}
build(,);
} void solve()
{
scanf("%d",&m);
for (int i=;i<m;i++)
{
char op[];
scanf("%s",op);
if (op[]=='M')
{
int a,b;
scanf("%d%d",&a,&b);
if (!ltree[a].del&&!ltree[b].del)
{
int fa=find(a),fb=find(b);
if (fa!=fb) merge(fa,fb);//不要忘记要判断两者不在同一个集合中
}
}
if (op[]=='K')
{
int a;
scanf("%d",&a);
if (ltree[a].del) puts("");
else
{
int fa=find(a);
printf("%d\n",ltree[fa].key);
Del(fa);
}
}
}
} int main()
{
init();
solve();
return ;
}

【裸裸的左偏树】BZOJ1455-罗马游戏的更多相关文章

  1. 【bzoj1455】【罗马游戏】左偏树+并查集(模板)

    Description 罗马皇帝很喜欢玩杀人游戏. 他的军队里面有n个人,每个人都是一个独立的团.最近举行了一次平面几何测试,每个人都得到了一个分数. 皇帝很喜欢平面几何,他对那些得分很低的人嗤之以鼻 ...

  2. 【BZOJ-1455】罗马游戏 可并堆 (左偏树)

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

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

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

  4. 【BZOJ1455】罗马游戏(左偏树)

    [BZOJ1455]罗马游戏(左偏树) 题面 BZOJ 然而权限题. 题解 左偏树模板题. #include<iostream> #include<cstdio> #inclu ...

  5. [bzoj1455]罗马游戏_左偏树_并查集

    罗马游戏 bzoj-1455 题目大意:给你n个人,2种操作,m次操作:1.将i号士兵所在的集合的最小值删除 2.合并i和j两个士兵所在的团体 注释:$1\le n\le 10^6$,$1\le m ...

  6. [BZOJ1455]罗马游戏(左偏树)

    用并查集和左偏树维护士兵的关系 Code #include <cstdio> #include <algorithm> #define N 1000010 using name ...

  7. 【BZOJ 1455】 1455: 罗马游戏 (可并堆-左偏树+并查集)

    1455: 罗马游戏 Description 罗马皇帝很喜欢玩杀人游戏. 他的军队里面有n个人,每个人都是一个独立的团.最近举行了一次平面几何测试,每个人都得到了一个分数. 皇帝很喜欢平面几何,他对那 ...

  8. BZOJ 1455 罗马游戏 左偏树

    题目大意:给定n个点,每一个点有一个权值,提供两种操作: 1.将两个点所在集合合并 2.将一个点所在集合的最小的点删除并输出权值 非常裸的可并堆 n<=100W 启示式合并不用想了 左偏树就是快 ...

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

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

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

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

随机推荐

  1. react 项目遇到的警告集锦

    1.  2.

  2. 在C++11中实现监听者模式

    参考文章:https://coderwall.com/p/u4w9ra/implementing-signals-in-c-11 最近在完成C++大作业时,碰到了监听者模式的需求. 尽管C++下也可以 ...

  3. Vue 脱坑记

    问题汇总 Q:安装超时(install timeout) 方案有这么些: cnpm : 国内对npm的镜像版本 /* cnpm website: https://npm.taobao.org/ */ ...

  4. 仿360影视网站模板html

    链接:http://pan.baidu.com/s/1mhIkV4s 密码:9wgq

  5. Android稳定性测试工具Monkey的使用

    综述    Monkey是一个命令行工具,它可以运行在我们的模拟器或者设备当中.它可以发送一些伪随机的用户事件流,例如点击.触摸.手势等.我们能够使用Monkey工具来对我们所开发的应用进行压力测试. ...

  6. 【shell】shell编程总结

    总结一下在写shell脚本时的常见注意事项: 1.shell脚本中的命令最好用命令的全路径,如果不知道全路径可以用which cmd查找命令的全路径. 2.shell脚本中定义环境变量用export ...

  7. SpringMVC_HelloWorld_03

    通过注解的方式实现一个简单的HelloWorld. 源码 一.新建项目 同SpringMVC_HelloWorld_01 不同的是springmvc配置文件的命名和路径,此处为src/springmv ...

  8. CSS3 object-fit 图像裁剪

    MDN定义 https://developer.mozilla.org/zh-CN/docs/Web/CSS/object-fit 该 object-fit CSS 属性指定替换元素的内容应该如何适应 ...

  9. nginx 各种配置

    first : mkdir /usr/local/nginx/conf/vhosts{网站配置}/usr/local/nginx/conf/vhosts/test.conf : server { li ...

  10. Python语言库pyttsx3

    这是一个文字转语音的python模块. 1. macos下安装的时候出现问题:  后来发现,Foundation, AppKit, PyObjCTools都不存在,主要原因是缺少依赖模块pyobjc, ...