bzoj1455
来源:互联网 发布:centos 6.5安装分区 编辑:程序博客网 时间:2024/06/08 00:42
只能说随机是个好东西比左偏树好写一点
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define MAX 1000010using namespace std;struct Heap{ Heap *son[2]; int val; Heap(int _):val(_) { son[0] = son[1] = NULL; } Heap() {}}*heap[MAX],mempool[MAX],*C = mempool + 1;Heap *Merge(Heap *x,Heap *y){ if(x == NULL) return y; if(y == NULL) return x; if(x->val > y->val) swap(x,y); bool k = rand()&1; x->son[k] = Merge(x->son[k],y); return x;}int points,asks;int src[MAX];bool killed[MAX];char s[10];int father[MAX];int Find(int x){ if(father[x] == x) return x; return father[x] = Find(father[x]);}int main(){ srand(19970806); cin >> points; for(int i = 1; i <= points; ++i) father[i] = i; for(int x,i = 1; i <= points; ++i) { scanf("%d",&x); heap[i] = new (C++)Heap(x); } cin >> asks; for(int x,y,i = 1; i <= asks; ++i) { scanf("%s",s); if(s[0] == 'M') { scanf("%d%d",&x,&y); if(killed[x] || killed[y]) continue; int fx = Find(x),fy = Find(y); if(fx == fy) continue; father[fy] = fx; heap[fx] = Merge(heap[fx],heap[fy]); } else { scanf("%d",&x); if(killed[x]) { puts("0"); continue; } int fx = Find(x); printf("%d\n",heap[fx]->val); killed[heap[fx] - mempool] = true; heap[fx] = Merge(heap[fx]->son[0],heap[fx]->son[1]); } } return 0;}
0 0
- bzoj1455
- bzoj1455 左偏堆
- bzoj1455: 罗马游戏
- 【BZOJ1455】罗马游戏
- bzoj1455: 罗马游戏
- bzoj1455 罗马游戏
- [bzoj1455]罗马游戏
- BZOJ1455: 罗马游戏
- bzoj1455 罗马游戏
- 【bzoj1455】罗马游戏
- 【左偏堆】bzoj1455罗马游戏
- bzoj1455罗马游戏
- 【bzoj1455】罗马游戏
- Bzoj1455 罗马游戏
- [bzoj1455]罗马游戏 左偏树
- BZOJ1455[罗马游戏]
- bzoj1455: 罗马游戏
- bzoj1455 罗马游戏
- TabControl 显示和隐藏选项卡
- bzoj 1922(dijkstra)
- 正则表达式
- 捕捉键盘移动(根据键盘移动view跟随上下)
- iOS设计模式
- bzoj1455
- JabRef中文乱码问题解决方法
- 获取所有文件的路径及文件对应标签(文件夹)
- XML解析
- 五种开源协议的比较(BSD,Apache,GPL,LGPL,MIT) – 整理
- java中创建file对象成功后,可以进行的操作
- 树莓派采集RS485数据
- Xutil网络请求
- web性能测试工具