link cut tree模板(LCT模板)
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模板)的更多相关文章
- Luogu P3690【模板】Link Cut Tree (LCT板题)
省选前刷道LCT板题(话说之前没做这道题-) CODE #include<bits/stdc++.h> using namespace std; inline void read(int ...
- LUOGU P3690 【模板】Link Cut Tree (lct)
传送门 解题思路 \(lct\)就是基于实链剖分,用\(splay\)来维护每一条实链,\(lct\)的维护对象是一棵森林.\(lct\)支持很多神奇的操作: \(1.\) \(access\):这是 ...
- 洛谷P3690 【模板】Link Cut Tree (LCT)
题目背景 动态树 题目描述 给定n个点以及每个点的权值,要你处理接下来的m个操作.操作有4种.操作从0到3编号.点从1到n编号. 0:后接两个整数(x,y),代表询问从x到y的路径上的点的权值的xor ...
- LuoguP3690 【模板】Link Cut Tree (LCT)
勉强算是结了个大坑吧或者才开始 #include <cstdio> #include <iostream> #include <cstring> #include ...
- LCT总结——概念篇+洛谷P3690[模板]Link Cut Tree(动态树)(LCT,Splay)
为了优化体验(其实是强迫症),蒟蒻把总结拆成了两篇,方便不同学习阶段的Dalao们切换. LCT总结--应用篇戳这里 概念.性质简述 首先介绍一下链剖分的概念(感谢laofu的讲课) 链剖分,是指一类 ...
- 洛谷P3690 [模板] Link Cut Tree [LCT]
题目传送门 Link Cut Tree 题目背景 动态树 题目描述 给定n个点以及每个点的权值,要你处理接下来的m个操作.操作有4种.操作从0到3编号.点从1到n编号. 0:后接两个整数(x,y),代 ...
- LuoguP3690 【模板】Link Cut Tree (动态树) LCT模板
P3690 [模板]Link Cut Tree (动态树) 题目背景 动态树 题目描述 给定n个点以及每个点的权值,要你处理接下来的m个操作.操作有4种.操作从0到3编号.点从1到n编号. 0:后接两 ...
- P3690 【模板】Link Cut Tree (动态树)
P3690 [模板]Link Cut Tree (动态树) 认父不认子的lct 注意:不 要 把 $fa[x]$和$nrt(x)$ 混 在 一 起 ! #include<cstdio> v ...
- 【刷题】洛谷 P3690 【模板】Link Cut Tree (动态树)
题目背景 动态树 题目描述 给定n个点以及每个点的权值,要你处理接下来的m个操作.操作有4种.操作从0到3编号.点从1到n编号. 0:后接两个整数(x,y),代表询问从x到y的路径上的点的权值的xor ...
- LG3690 【模板】Link Cut Tree (动态树)
题意 给定n个点以及每个点的权值,要你处理接下来的m个操作.操作有4种.操作从0到3编号.点从1到n编号. 0:后接两个整数(x,y),代表询问从x到y的路径上的点的权值的xor和.保证x到y是联通的 ...
随机推荐
- ChemDraw中化学信息怎么通过Excel搜索
用户可以通过ChemDraw for Excel插件功能在Office Excel中建立ChemOffice菜单将ChemOffice和Excel结合使用,使用电子表格的最大优势之一就是可以清晰查看并 ...
- JQuery------实现鼠标摁下抬起时div背景色改变
作用:使用自定义一个按钮 代码: <div class = 'btn'>按钮</div> $(".btn").mousedown(function () { ...
- Perfmon - Windows 自带系统监测工具
本文转载自oscar999 一. 简述 可以用于监视CPU使用率.内存使用率.硬盘读写速度.网络速度等. Perfmon提供了图表化的系统性能实时监视器.性能日志和警报管理,系统的性能日志可定义为二进 ...
- js 中导出excel 较长数字串会变成科学计数法(转载)
在做项目中,碰到如题的问题.比如要将居民的信息导出到excel中,居民的身份证号码因为长度过长(大于10位),excel会自动的将过长的数字串转换成 科学计数法.现在网上找到解决方案之一: (在数字串 ...
- SpringMvc三大组件详解
SpringMvc框架结构图 处理器映射器:用户请求路径到Controller方法的映射 处理器适配器:根据handler(controlelr类)的开发方式(注解开发/其他开发) 方式的不同区寻找不 ...
- onbeforeunload 适用DOM 0级,不适用 DOM 2级
你可以在控制台试下: window.addEventListener("beforeunload", function () { return 'ss'; }); 我这里 chro ...
- 160607、springmvc+spring使用taskExecutor
第一步:导入spring core的jar+springmvc的jar 第二步:springmvc的配置文件中 <bean id="taskExecutor" class=& ...
- 安装mysql最后一步未响应,卡死。(解决方法mySql5.5,以及安装教程)
安装教程:http://www.server110.com/mysql/201308/784.html 重装mysql的时候,总是在提交配置后的最后一步,安装失败,进程管理器里显示程序无响应,mysq ...
- 百度jQuery库
<script src="http://apps.bdimg.com/libs/jquery/1.11.1/jquery.js"></script>
- logback.xml解读----日志配置解读
初次接触javaweb项目的日志是log4j文件,但是后来发现通过配置logback.xml文件实现日志输出非常好用.经过上午的学习,现总结如下: 直接上配置文件和注释: <?xml versi ...