【BZOJ】1455 罗马游戏 左偏树
2017-05-04 18:10
381 查看
题目传送门
这题和洛谷上的左偏树模板的解题思路是一模一样的,所以只要贴上左偏树的模板就好了。
附上AC代码:
(因为这题需要权限,而我又没有氪金,所以交这题时我用的是他的号。别问我是怎么知道他的密码的)
这题和洛谷上的左偏树模板的解题思路是一模一样的,所以只要贴上左偏树的模板就好了。
附上AC代码:
#include <cstdio> #include <cctype> #include <algorithm> #define N 1000010 using namespace std; int n,m,dis ,w ,x,y,f ,ls ,rs ; void read(int& a){ static char c=getchar();a=0;int f=1; while (!isdigit(c)) {if (c=='-') f=-1;c=getchar();} while (isdigit(c)) a=a*10+c-'0',c=getchar(); } int gf(int x){ while (f[x]) x=f[x]; return x; } int hb(int a,int b){ if (a*b==0) return a+b; if (w[a]>w[b]||(w[a]==w[b]&&a>b)) swap(a,b); rs[a]=hb(rs[a],b); f[rs[a]]=a; if (dis[ls[a]]<dis[rs[a]]) swap(ls[a],rs[a]); dis[a]=dis[rs[a]]+1; return a; } int main(void){ read(n),dis[0]=-1; for (int i=1; i<=n; ++i) read(w[i]); read(m); while (m--){ char c=getchar(); while (c!='M'&&c!='K') c=getchar(); switch (c){ case 'M': read(x),read(y); if (w[x]==-1||w[y]==-1) continue; x=gf(x),y=gf(y); if (x!=y) hb(x,y); break; case 'K': read(x); if (w[x]==-1) puts("0"); else { x=gf(x),printf("%d\n",w[x]),w[x]=-1; f[ls[x]]=f[rs[x]]=0,hb(ls[x],rs[x]); } break; } } }orzLYF大佬,如此的强,在半个月前就把这题A掉了。别问我是怎么知道的。
(因为这题需要权限,而我又没有氪金,所以交这题时我用的是他的号。别问我是怎么知道他的密码的)
相关文章推荐
- 【裸裸的左偏树】BZOJ1455-罗马游戏
- BZOJ1455 罗马游戏 【左偏树】
- bzoj 1455: 罗马游戏 左偏树+并查集
- BZOJ 1455: 罗马游戏 左偏树 or pb_ds
- 【bzoj1455】【罗马游戏】左偏树+并查集(模板)
- BZOJ 1455 罗马游戏 [右偏树(误)][左偏树]
- 【BZOJ-1455】罗马游戏 可并堆 (左偏树)
- [BZOJ1455]罗马游戏 左偏树+并查集
- BZOJ 1455 罗马游戏 左偏树
- 【bzoj1455】【罗马游戏】左偏树+并查集(模板)
- bzoj1455 罗马游戏 左偏树
- [bzoj1455]罗马游戏_左偏树_并查集
- bzoj1455 罗马游戏(左偏树(可并堆)+ 并查集)
- bzoj 1455: 罗马游戏 左偏树
- BZOJ 1455 罗马游戏 ——左偏树
- [bzoj1455]罗马游戏 左偏树
- BZOJ 1455: 罗马游戏 左偏树裸题
- [BZOJ1455] 罗马游戏|左偏树
- bzoj 1455: 罗马游戏(可并堆)
- BZOJ 1455: 罗马游戏 [可并堆]