update:2017.09.26

 #include <bits/stdc++.h>

 using namespace std;

 struct Link_Cut_Tree
{
static const int MAXN = + ; int ch[MAXN][], fa[MAXN], rev[MAXN], sz[MAXN];
int sk[MAXN]; bool isroot(int x)
{
return ch[fa[x]][] != x && ch[fa[x]][] != x;
} void reverse(int x)
{
rev[x] ^= , swap(ch[x][],ch[x][]);
} void update(int x)
{
sz[x] = sz[ch[x][]] + sz[ch[x][]] +;
} void push_down(int x)
{
if(!rev[x]) return ;
if(ch[x][]) reverse(ch[x][]);
if(ch[x][]) reverse(ch[x][]);
rev[x]=;
} void rotate(int x)
{
int f = fa[x], gf = fa[f];
int t1 = ( x != ch[f][]), t2 = ( f != ch[gf][]), tmp = ch[x][^t1];
if(!isroot(f)) ch[gf][^t2] = x;
fa[tmp] = f, fa[x] = gf, ch[x][^t1] = f, fa[f] = x, ch[f][^t1] = tmp;
update(f);
} void splay(int x)
{
int top = ;
sk[++top] = x;
for(int i = x; !isroot(i); i = fa[i]) sk[++top] = fa[i];
while(top) push_down(sk[top--]);
for(int f = fa[x], gf = fa[f]; !isroot(x); rotate(x), f = fa[x],gf = fa[f])
if(!isroot(f))
rotate((x==ch[f][]) ^ (f==ch[gf][]) ? x : f);
update(x);
} void access(int x)
{
for(int p = ; x; p = x, x = fa[x])
splay(x), ch[x][] = p, update(x);
} void makeroot(int x)
{
access(x), splay(x), reverse(x);
} int findroot(int x)
{
access(x), splay(x);
while(ch[x][]) x = ch[x][];
return x;
}
void link(int x,int y)
{
makeroot(x), fa[x] = y;
} void cut(int x,int y)
{
makeroot(x), access(y), splay(y);
if(ch[y][] == x) ch[y][] = fa[x] = ;
update(y);
} void debug(void)
{
for(int i=;i<=;i++)
printf("%d %d %d %d %d %d %d\n",i,fa[i],ch[i][],ch[i][],rev[i],sz[i]);
}
}lct; int main(void)
{ return ;
}

link cut tree模板(LCT模板)的更多相关文章

  1. Luogu P3690【模板】Link Cut Tree (LCT板题)

    省选前刷道LCT板题(话说之前没做这道题-) CODE #include<bits/stdc++.h> using namespace std; inline void read(int ...

  2. LUOGU P3690 【模板】Link Cut Tree (lct)

    传送门 解题思路 \(lct\)就是基于实链剖分,用\(splay\)来维护每一条实链,\(lct\)的维护对象是一棵森林.\(lct\)支持很多神奇的操作: \(1.\) \(access\):这是 ...

  3. 洛谷P3690 【模板】Link Cut Tree (LCT)

    题目背景 动态树 题目描述 给定n个点以及每个点的权值,要你处理接下来的m个操作.操作有4种.操作从0到3编号.点从1到n编号. 0:后接两个整数(x,y),代表询问从x到y的路径上的点的权值的xor ...

  4. LuoguP3690 【模板】Link Cut Tree (LCT)

    勉强算是结了个大坑吧或者才开始 #include <cstdio> #include <iostream> #include <cstring> #include ...

  5. LCT总结——概念篇+洛谷P3690[模板]Link Cut Tree(动态树)(LCT,Splay)

    为了优化体验(其实是强迫症),蒟蒻把总结拆成了两篇,方便不同学习阶段的Dalao们切换. LCT总结--应用篇戳这里 概念.性质简述 首先介绍一下链剖分的概念(感谢laofu的讲课) 链剖分,是指一类 ...

  6. 洛谷P3690 [模板] Link Cut Tree [LCT]

    题目传送门 Link Cut Tree 题目背景 动态树 题目描述 给定n个点以及每个点的权值,要你处理接下来的m个操作.操作有4种.操作从0到3编号.点从1到n编号. 0:后接两个整数(x,y),代 ...

  7. LuoguP3690 【模板】Link Cut Tree (动态树) LCT模板

    P3690 [模板]Link Cut Tree (动态树) 题目背景 动态树 题目描述 给定n个点以及每个点的权值,要你处理接下来的m个操作.操作有4种.操作从0到3编号.点从1到n编号. 0:后接两 ...

  8. P3690 【模板】Link Cut Tree (动态树)

    P3690 [模板]Link Cut Tree (动态树) 认父不认子的lct 注意:不 要 把 $fa[x]$和$nrt(x)$ 混 在 一 起 ! #include<cstdio> v ...

  9. 【刷题】洛谷 P3690 【模板】Link Cut Tree (动态树)

    题目背景 动态树 题目描述 给定n个点以及每个点的权值,要你处理接下来的m个操作.操作有4种.操作从0到3编号.点从1到n编号. 0:后接两个整数(x,y),代表询问从x到y的路径上的点的权值的xor ...

  10. LG3690 【模板】Link Cut Tree (动态树)

    题意 给定n个点以及每个点的权值,要你处理接下来的m个操作.操作有4种.操作从0到3编号.点从1到n编号. 0:后接两个整数(x,y),代表询问从x到y的路径上的点的权值的xor和.保证x到y是联通的 ...

随机推荐

  1. 去除 \ufeff

    语言:python 编程工具:pycharm 硬件环境:win10 64位 读取文件过程中发现一个问题:已有记事本文件(非空),转码 UTF-8,复制到pycharm中,在开始位置打印结果会出现  \ ...

  2. phpcms V9内容页调用标签

    1.页面标题:{$title} 2.发表时间:{$inputtime} 3.内容来源:{$copyfrom} 4.文章内容:{$content} 5.缩略图地址:{$thumb} 6.组图列表: {l ...

  3. 666:放苹果(划分dp)

    666:放苹果 查看 提交 统计 提问 总时间限制:  1000ms 内存限制:  65536kB 描述 把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示 ...

  4. 解决多指操作放大缩小 指针错误 java.lang.IllegalArgumentException: pointerIndex out of range

    /** Custom your own ViewPager to extends support ViewPager. java source: */ /** Created by azi on 20 ...

  5. HDU 4348 To the moon(可持久化线段树)

    To the moon Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Tota ...

  6. Spring WebSocket实现消息推送

    第一步: 添加Spring WebSocket的依赖jar包 (注:这里使用maven方式添加 手动添加的同学请自行下载相应jar包放到lib目录) <!-- 使用spring websocke ...

  7. 关于ln(link)命令

    一. ln分为硬链接和软链接. 二. 硬链接命令为: ln test/a.text hard.text 1. 这样hard.text拥有 test目录下a.text相同的i节点(inode的id号)和 ...

  8. 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'information_schema.PROFILING.SEQ' which is not functionally dependent on columns in GROUP BY clause

    解决方法一: SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','')); 优点:不用重启mysql 缺点:重启mysql后还会 ...

  9. Python 3.5 中的异步HTTP请求写法

    Python 3.5 增加了对async def and await的支持,同样的异步代码看起来干净了很多,也更易读. import aiohttp import asyncio async def ...

  10. 解决Xshell中使用hbase shell backspace无法删除

    进入到XShell 文件 –> 属性 –> 终端 –> 键盘 在 DELETE键序列 和 BACKSPACE键序列 中都选择 ASCII 127 最后进入 Hbase 命令行测试,可 ...