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. Linux命令:head命令详解

    概述:head命令用于显示文件文字区块 1.格式 head [参数][文件] 2.参数 -q 隐藏文件名 -v 显示文件名 -c<字节> 显示字节数 -n<行数> 显示的行数 ...

  2. photoshop cc 版本安装失败解决办法

    好久没有碰ps,看了下在ps版本都到cc了.忍不住也想尝试最新版本,但是安装出现了很多问题,导致我花了很多时间才搞定,现在分享给大家几点经验吧. Exit Code: Please see speci ...

  3. WPF自定义DataGrid分页控件

    新建Custom Control,名:PagingDataGrid 打开工程下面的Themes\Generic.xaml xaml里面代码替换如下 <Style x:Key="{x:T ...

  4. 如何使rdlc报表的表头在每一页都显示

    想要使表格的表头在每一行都显示,直接在表格的属性设置界面中设置是无效的,应该算是一个BUG,如图: 但还是可以实现的,实现方法如下,这个实现方法从网上得到 开发工具: Visual Studio 20 ...

  5. dedecms 文章内容文章名字和文章网址的调用

    文章标题: <a href="{dede:field name='arcurl'/}">{dede:field.title/}</a> 本文章网址: < ...

  6. objective-c(初始化)

    objective-c(初始化) 创建对象 (编程语言 Objective-C 2.0) 1.类对象与实例化 类的定义完成后,编译器在内存中自动生成唯一的类对象,实例对象都是通过调用类对象的类方法生成 ...

  7. 1. android

    http://blog.csdn.net/mirkerson/article/details/7238815

  8. Java吸收换行符

            今天做题遇到的--         由于读入的字符串可能包含空格,所以采用nextLine. int n = sc.nextInt(); for(int i=0; i<n; i+ ...

  9. 快学Scala第一部分

    转载: 1.变量声明 val answer = 8 * 5 + 2; //常量 var counter = 0;    //变量 //在必要的时候 ,可以指定类型 val greeting:Strin ...

  10. MySQL表损坏预防与修复

    1.       表损坏的原因分析 以下原因是导致mysql 表毁坏的常见原因: 1. 服务器突然断电导致数据文件损坏. 2. 强制关机,没有先关闭mysql 服务. 3. mysqld 进程在写表时 ...