【bzoj1455】罗马游戏
1455: 罗马游戏
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 1061 Solved: 439
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
100 90 66 99 10
7
M 1 5
K 1
K 1
M 2 3
M 3 4
K 5
K 4
Sample Output
100
0
66
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<algorithm>
using namespace std;
int n,m,a[],f[],die[],r[],l[],dist[];
inline int read()
{
int x=,f=; char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') f=-; ch=getchar();}
while(isdigit(ch)) {x=x*+ch-''; ch=getchar();}
return x*f;
}
int find(int x){return f[x]==x?x:f[x]=find(f[x]);}
int merge(int x,int y)
{
if(!x) return y;
if(!y) return x;
if(a[x]>a[y]) swap(x,y);
r[x]=merge(r[x],y);
if(dist[r[x]]>dist[l[x]]) swap(r[x],l[x]);
dist[x]=dist[r[x]]+;
return x;
}
int main()
{
freopen("cin.in","r",stdin);
freopen("cout.out","w",stdout);
n=read();
for(int i=;i<=n;i++) {a[i]=read(); f[i]=i;}
m=read(); dist[]=-;
for(int i=;i<=m;i++)
{
char ch=getchar();
if(ch=='M')
{
int x=read(),y=read();
if(die[x]||die[y]) continue;
x=find(x); y=find(y);
if(x!=y)
{
int t=merge(x,y);
f[x]=f[y]=t;
}
}
else
{
int x=read();
if(die[x]) printf("0\n");
else
{
x=find(x); die[x]=;
printf("%d\n",a[x]);
f[x]=merge(l[x],r[x]);
f[f[x]]=f[x];
}
}
}
return ;
}
【bzoj1455】罗马游戏的更多相关文章
- [bzoj1455]罗马游戏_左偏树_并查集
罗马游戏 bzoj-1455 题目大意:给你n个人,2种操作,m次操作:1.将i号士兵所在的集合的最小值删除 2.合并i和j两个士兵所在的团体 注释:$1\le n\le 10^6$,$1\le m ...
- [BZOJ1455]罗马游戏 左偏树+并查集
1455: 罗马游戏 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 2285 Solved: 994[Submit][Status][Discuss] ...
- Bzoj1455 罗马游戏
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1622 Solved: 679 Description 罗马皇帝很喜欢玩杀人游戏. 他的军队里面有n个人 ...
- 【数据结构】bzoj1455罗马游戏
Description 罗马皇帝很喜欢玩杀人游戏. 他的军队里面有n个人,每个人都是一个独立的团.最近举行了一次平面几何测试,每个人都得到了一个分数. 皇帝很喜欢平面几何,他对那些得分很低的人嗤之以鼻 ...
- bzoj1455: 罗马游戏 + bzoj2809: Dispatching(可并堆)
昨天看了可并堆是什么,写的是左偏树 大概就是一棵树 1.有左偏性质,即当前根到左叶子节点距离比到右叶子节点距离大 2.有堆性质,堆顶关键字比子树关键字小 合并两个堆的时候,关键字大的插入到关键字小的那 ...
- BZOJ1455 罗马游戏 左偏树 可并堆
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1455 题意概括 n个人,2种操作. 一种是合并两个人团,一种是杀死某一个人团的最弱的人. 题解 左 ...
- BZOJ1455——罗马游戏
1.题目大意:维护一个数据结构,可以实现合并操作,还能询问最小值 2.分析:这种问题当然是可并堆啦 随便写了一个左偏树QAQ #include <cstdio> #include < ...
- [BZOJ1455]罗马游戏(左偏树)
用并查集和左偏树维护士兵的关系 Code #include <cstdio> #include <algorithm> #define N 1000010 using name ...
- BZOJ1455罗马游戏
左偏树裸题. 题面描述让人意识到了平面几何的重要性. //Achen #include<algorithm> #include<iostream> #include<cs ...
- 【BZOJ1455】罗马游戏(左偏树)
[BZOJ1455]罗马游戏(左偏树) 题面 BZOJ 然而权限题. 题解 左偏树模板题. #include<iostream> #include<cstdio> #inclu ...
随机推荐
- zoj-3963 Heap Partition(贪心+二分+树状数组)
题目链接: Heap Partition Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge A sequence ...
- JS同源策略和跨域访问
同源策略(Same origin policy)是一种约定,它是浏览器最核心也最基本的安全功能,如果缺少了同源策略,则浏览器的正常功能可能都会受到影响.可以说Web是构建在同源策略基础之上的,浏览器只 ...
- VS调试配置外网可访问
1.首先找到项目的配置文件夹(一般是隐藏的) 2.在里面的config文件夹找到applicationhost.config配置文件,打开,在sites节点找到你项目的那个site配置,新建一个绑定:
- 关于json解析和所需jar
以解析字符串数组为例: String parameter= [{"id":"pdTNKcY1YS55oG2M",.......}] 1. 关于net.sf.js ...
- HDU - 6185 :Covering(矩阵乘法&状态压缩)
Bob's school has a big playground, boys and girls always play games here after school. To protect bo ...
- CodeForces - 662A:Gambling Nim (求有多少个子集其异或为S)(占位)
As you know, the game of "Nim" is played with n piles of stones, where the i-th pile initi ...
- 【转载】Python正则表达式指南
本文转自:http://www.cnblogs.com/huxi/archive/2010/07/04/1771073.html#!comments 1. 正则表达式基础 1.1. 简单介绍 正则表达 ...
- Kafka源码深度解析-序列7 -Consumer -coordinator协议与heartbeat实现原理
转自:http://blog.csdn.net/chunlongyu/article/details/52791874 单线程的consumer 在前面我们讲过,KafkaProducer是线程安全的 ...
- iOS6 自动布局 入门–Auto Layout
目前为止,即使你的界面设计是在合理的复杂度内,你也必须要为之写许多代码来适应变化的布局.现在我相信你会很高兴听到这种情况将不会发生了-对于iPhone与iPad IOS6 带来了一个非常了不起的特征: ...
- ACM学习历程—SNNUOJ 1239 Counting Star Time(树状数组 && 动态规划 && 数论)
http://219.244.176.199/JudgeOnline/problem.php?id=1239 这是这次陕西省赛的G题,题目大意是一个n*n的点阵,点坐标从(1, 1)到(n, n),每 ...