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. 解决spring boot中rest接口404,500等错误返回统一的json格式

    在开发rest接口时,我们往往会定义统一的返回格式,列如: { "status": true, "code": 200, "message" ...

  2. 【转】Native Thread for Win32 B-Threads Synchronization(通俗易懂,非常好)

    http://www.bogotobogo.com/cplusplus/multithreading_win32B.php   Synchronization Between Threads In t ...

  3. Mock利器:PowerMock

    powerMock不仅支持接口mock,final类.静态类.静态方法.私有方法都支持mock,还是很强大的: 1.gradle引用: myonlycompile('org.powermock:pow ...

  4. 统计nginx进程占用的物理内存

    #!/usr/bin/env python #-*- coding:utf-8 -*- ''' 统计nginx进程占用的物理内存 ''' import os import sys import sub ...

  5. BaseAdapter<T> 重写 createViewFromResource实现界面,刷新,加载,移除

    import java.util.ArrayList; import java.util.List; import android.content.Context; import android.vi ...

  6. JavaIo编程基础复习

    什么是Io io是指Input和Output,指输入和输出 Input是指外部读入数据到内存,例如读取一个文件,或者从网络中读取 Output是指把内存中的数据输出到外部,例如写文件,输出到网络 什么 ...

  7. freenas 11.2踩过的坑

    修改SMB最小协议 服务器最小协议由FreeNAS上的sysctl控制. 在System-> Tunables 下添加sysctl来使其永久化:Variable = freenas.servic ...

  8. JavaScript学习(5)-Image对象和动态HTML

    JavaScript学习5 1.image 对象 对象引用 document.images[n] document.images["imageName"] document.ima ...

  9. Nagle's Algorithm and TCP_NODELAY

    w非全尺寸分组的发送条件 HTTP The Definitive Guide TCP has a data stream interface that permits applications to ...

  10. 学习IPFS

    注:以下所有操作均在CentOS 6.8 x86_64位系统下完成. IPFS(InterPlanetary File System)是一个点对点的分布式超媒体分发协议,被认为是最有可能取代HTTP的 ...