lct入门题?

得换根了吧TAT

这大概不是很成熟的版本..

 #include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cstdio>
using namespace std; const int Maxn = ; int ch[Maxn][],p[Maxn],flip[Maxn];
int n,m; const int D=;
char in[D],out[*],*I=in,*O=out;
#define gc (*I++)
#define pc(x) ((*O++)=x)
template <typename Q>
void gt(Q&x) {
static char c,f;
for(c=gc,f=;!isdigit(c);c=gc)if(c=='-') f=;
for(x=;isdigit(c);c=gc) x=x*+c-'';
f && (x=-x);
} template <typename Q>
void pt(Q x){
static char stk[];
static int top;
top=;
if(x==) pc('');
for(;x;x/=) stk[++top] = x%+'';
for(;top;top--) pc(stk[top]);
} void down(int x){
if(flip[x]) {
swap(ch[x][],ch[x][]);
flip[ch[x][]]^=;
flip[ch[x][]]^=;
flip[x]=;
}
} bool isroot(int x){
return ch[p[x]][]!=x && ch[p[x]][]!=x;
} void rotate(int x) {
int y=p[x],z=p[y];
int l=ch[y][]==x,r=l^;
if(!isroot(y)) ch[z][ch[z][]==y]=x;
p[ch[x][r]]=y;
p[y]=x;
p[x]=z; ch[y][l]=ch[x][r];
ch[x][r]=y;
} int stk[Maxn],top;
void splay(int x){
stk[top=]=x;
for(int t=x;!isroot(t);t=p[t]) stk[++top]=p[t];
for(;top;top--) down(stk[top]); for(;!isroot(x);){
int y=p[x],z=p[y];
if(!isroot(y)){
if( (ch[y][]==x)^(ch[z][]==y) )
rotate(x);else rotate(y);
}
rotate(x);
}
} void access(int x){
for(int t=;x;x=p[t=x]){
splay(x);
ch[x][]=t;
}
} int getroot(int x){
for(access(x),splay(x);ch[x][];x=ch[x][]);
return x;
} void newroot(int x) {
access(x);
splay(x);
flip[x]^=;
} void cut(int x){
access(x);
splay(x);
p[ch[x][]]=;
ch[x][]=;
} void combine(int x,int y) {
newroot(x);
p[x]=y;
} void work() {
gt(n),gt(m);
char c;
int a,b;
for(int i=;i<=m;i++) {
for(;c=gc,c!='Q' && c!='C' &&c!='D';);
gt(a),gt(b);
if(c=='Q') printf("%s\n",getroot(a)==getroot(b)?"Yes" : "No");
else if(c=='C') combine(a,b);
else newroot(a),cut(b);
}
} int main() {
#ifdef DEBUG
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
fread(in,,D,stdin); work(); return printf(out),;
}

bzoj2049: [Sdoi2008]Cave 洞穴勘测的更多相关文章

  1. BZOJ2049 SDOI2008 Cave 洞穴勘测 【LCT】

    BZOJ2049 SDOI2008 Cave 洞穴勘测 Description 辉辉热衷于洞穴勘测.某天,他按照地图来到了一片被标记为JSZX的洞穴群地区.经过初步勘测,辉辉发现这片区域由n个洞穴(分 ...

  2. 【LCT】BZOJ2049 [SDOI2008]Cave 洞穴勘测

    2049: [Sdoi2008]Cave 洞穴勘测 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 10059  Solved: 4863[Submit ...

  3. [BZOJ2049][Sdoi2008]Cave 洞穴勘测 LCT模板

    2049: [Sdoi2008]Cave 洞穴勘测 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 9705  Solved: 4674[Submit] ...

  4. [bzoj2049][Sdoi2008]Cave 洞穴勘测_LCT

    Cave 洞穴勘测 bzoj-2049 Sdoi-2008 题目大意:维护一个数据结构,支持森林中加边,删边,求两点连通性.n个点,m个操作. 注释:$1\le n\le 10^4$,$1\le m\ ...

  5. [BZOJ2049] [SDOI2008] Cave 洞穴勘测 (LCT)

    Description 辉辉热衷于洞穴勘测.某天,他按照地图来到了一片被标记为JSZX的洞穴群地区.经过初步勘测,辉辉发现这片区域由n个洞穴(分别编号为1到n)以及若干通道组成,并且每条通道连接了恰好 ...

  6. BZOJ2049: [Sdoi2008]Cave 洞穴勘测 Link-Cut-Tree 模板题

    传送门 搞了这么长时间Splay终于可以搞LCT了,等等,什么是LCT? $LCT$就是$Link-Cut-Tree$,是维护动态树的一个很高效的数据结构,每次修改和查询的均摊复杂度为$O(logN) ...

  7. BZOJ2049——[Sdoi2008]Cave 洞穴勘测

    1.题目大意:就是一个动态维护森林联通性的题 2.分析:lct模板题 #include <stack> #include <cstdio> #include <cstdl ...

  8. bzoj2049 [Sdoi2008]Cave 洞穴勘测 link cut tree入门

    link cut tree入门题 首先说明本人只会写自底向上的数组版(都说了不写指针.不写自顶向下QAQ……) 突然发现link cut tree不难写... 说一下各个函数作用: bool isro ...

  9. bzoj2049: [Sdoi2008]Cave 洞穴勘测 lct裸题

    题意:三种操作一种摧毁一条边,一种链接一条边,一种查询两个点是否联通 题解:lct的link和cut即可 /********************************************** ...

随机推荐

  1. idea 配置node Run

    1.node 2.nodemon 支持热部署 3.supervisor  支持执部署

  2. 【Ural1057】幂和的数量

    [题目描述] 写一个程序来计算区间[X,Y]内满足如下条件的整数个数:它恰好等于K个互不相等的B的整数幂之和. 举个例子.令X=15,Y=20,K=2,B=2.在这个例子中,区间[15,20]内有3个 ...

  3. 在CentOS 6.3中安装与配置JDK-7

    在CentOS 6.3中安装与配置JDK-7 来源:互联网 作者:佚名 时间:02-07 16:28:33 [大 中 小] 在CentOS-6.3中安装与配置JDK-7,有需要的朋友可以参考下 安装说 ...

  4. sendmail服务器的安装

    1.检查sendmail是否已安装: rpm -qa | grep sendmail   2.yum -y install sendmail    安装 yum -y remove sendmail  ...

  5. Linux nohup命令详解

    nohup命令及其输出文件                                                                                       ...

  6. 使用Thinkphp框架开发移动端接口

     本文给大家分享的是使用thinkphp框架开发移动端接口的2种方法,一种是开发API,另外一种是实现移动端访问自动切换移动主题模板,从而实现伪app访问,下面我们就来详细看下如何实现吧. 方案一:给 ...

  7. mysql数据类型——整型INT(m)

    1.整形分为四种 tinyint smallint mediumint int bigint 注意: 右侧的取值范围是在未加unsigned关键字的情况下,如果加了unsigned,则最大值翻倍,如t ...

  8. PhotoSwipe.js 相册展示插件学习

    PhotoSwipe.js官网:http://photoswipe.com/,在这个网站上可以下载到PhotoSwipe的文件以及相关的例子. 这个组件主要是用来展示图片.相册用的,还是很实用的. 一 ...

  9. Ajax实现的长轮询不阻塞同一时间内页面的其他Ajax请求(同域请求)

    最近要做一个来电的弹屏功能,利用OM 系统的接口,OM系统发送请求到接口程序,分析数据添加到mysql数据库中,然后把最新的数据id 跟今日来电的总的数量存储到memcache 中.弹屏程序根据读取的 ...

  10. while if 循环判断

    temp=input("猜一下我想的那个数字吧:") guess=int(temp) while guess!=8: temp=input("诶呀错误了在输入一次吧:&q ...