LCT模板(无讲解)
怎么说呢,照着打一遍就自然理解了,再打一遍就会背了,再打一遍就会推了。
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
const int maxn=3E5+;
int fa[maxn],son[maxn][],val[maxn],ans[maxn],n,m,opt,x,y,z;
bool tag[maxn];
bool notroot(int x){return son[fa[x]][]==x||son[fa[x]][]==x;}
void update(int x){ans[x]=ans[son[x][]]^ans[son[x][]]^val[x];}
void pushr(int x)
{
swap(son[x][],son[x][]);
tag[x]^=;
}
void pushdown(int x)
{
if(tag[x])
{
if(son[x][])pushr(son[x][]);
if(son[x][])pushr(son[x][]);
tag[x]=;
}
}
void rotate(int x,int c)
{
int y=fa[x];
fa[x]=fa[y];
son[y][!c]=son[x][c];
if(son[x][c])fa[son[x][c]]=y;
if(notroot(y)&&son[fa[y]][]==y)son[fa[y]][]=x;
else if(notroot(y))son[fa[y]][]=x;
son[x][c]=y;
fa[y]=x;
update(y);
update(x);
}
void down(int x)
{
if(!notroot(x)){pushdown(x);return;}
down(fa[x]);
pushdown(x);
}
void splay(int x)
{
down(x);
while(true)
{
int y=fa[x];
if(!notroot(x))break;
if(!notroot(y))
{
if(son[y][]==x)rotate(x,);
else rotate(x,);
break;
}
if(son[fa[y]][]==y)
{
if(son[y][]==x)rotate(y,),rotate(x,);
else rotate(x,),rotate(x,);
}
else
{
if(son[y][]==x)rotate(y,),rotate(x,);
else rotate(x,),rotate(x,);
}
}
}
void access(int x)
{
for(int y=;x;y=x,x=fa[x])
splay(x),son[x][]=y,update(x);
}
void makeroot(int x)
{
access(x);
splay(x);
pushr(x);
}
int findroot(int x)
{
access(x);
splay(x);
while(son[x][])pushdown(x),x=son[x][];
splay(x);
return x;
}
void split(int x,int y)
{
makeroot(x);
access(y);
splay(y);
}
void link(int x,int y)
{
makeroot(x);
if(findroot(y)!=x)fa[x]=y;
}
void cut(int x,int y)
{
makeroot(x);
if(findroot(y)==x&&fa[y]==x&&!son[y][])
{
fa[y]=son[x][]=;
update(x);
update(y);
}
}
int main()
{
ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=;i<=n;++i)cin>>val[i];
while(m--)
{
cin>>opt>>x>>y;
if(opt==)
{
split(x,y);
cout<<ans[y]<<endl;
}
else if(opt==)link(x,y);
else if(opt==)cut(x,y);
else
{
splay(x);
val[x]=y;
}
}
return ;
}
LCT模板(无讲解)的更多相关文章
- LCT模板
之前一直用的LCT模板,因为其实个人对LCT和Splay不是很熟,所以用起来总觉得略略的坑爹,过了一段时间就忘了,但事实上很多裸的LCT要改的东西是不多的,所以今天写了些注释,以后可能套起模板来会得心 ...
- LCT 模板及套路总结
这一个月貌似已经考了无数次\(LCT\)了..... 保险起见还是来一发总结吧..... A. LCT 模板 \(LCT\) 是由大名鼎鼎的 \(Tarjan\) 老爷发明的. 主要是用来维护树上路径 ...
- [洛谷P1501] [国家集训队]Tree II(LCT模板)
传送门 这是一道LCT的板子题,说白了就是在LCT上支持线段树2的操作. 所以我只是来存一个板子,并不会讲什么(再说我也不会,只能误人子弟2333). 不过代码里的注释可以参考一下. Code #in ...
- LuoguP3690 【模板】Link Cut Tree (动态树) LCT模板
P3690 [模板]Link Cut Tree (动态树) 题目背景 动态树 题目描述 给定n个点以及每个点的权值,要你处理接下来的m个操作.操作有4种.操作从0到3编号.点从1到n编号. 0:后接两 ...
- Miller Robbin测试模板(无讲解)
想着费马定理和二次探测定理就能随手推了. 做一次是log2n的. #include<bits/stdc++.h> using namespace std; typedef long lon ...
- NTT模板(无讲解)
#include<bits/stdc++.h>//只是在虚数部分改了一下 using namespace std; typedef long long int ll; ; ; ; ; ll ...
- FFT模板(无讲解)
#include<bits/stdc++.h> using namespace std; ; const double pi=3.1415926535898; ],len; struct ...
- Luogu 3690 LCT - 模板
推荐几篇比较好的博客: FlashHu 的 讲解比较好 : 传送门 Candy 的 代码~ : 传送门 以及神犇Angel_Kitty的 学习笔记: 传送门 Code V 模板 #include< ...
- BZOJ3282: Tree (LCT模板)
Description 给定N个点以及每个点的权值,要你处理接下来的M个操作. 操作有4种.操作从0到3编号.点从1到N编号. 0:后接两个整数(x,y),代表询问从x到y的路径上的点的权值的xor和 ...
随机推荐
- varnish 相关说明
一.关于Varnish Varnish 是一款高性能且开源的反向代理服务器和 HTTP 加速器,其采用全新的软件体系机构,和现在的硬件体系紧密配合,与传统的 squid 相比,varnish 具有性能 ...
- redis4.0 cluster搭建
cd /root/tools wget http://pnxcvm0bq.bkt.clouddn.com/redis-4.0.9.tar.gz tar -zxvf redis-4.0.9.tar.gz ...
- word模板导出的几种方式:第二种:C#通过模板导出Word(文字,表格,图片) 占位符替换
原文出处:https://www.cnblogs.com/ilefei/p/3508463.html 一:模板的创建 (注意文件后缀只能是.docx或.doct) 在需要位置 插入-文档部件-域, ...
- Linux环境——MySQL安装及配置(8.0版本)
虚拟机环境是Linux Red Hat Enterprlse Linux (64位),本次安装的是Mysql 8.0版本. 由于有经验了,所以又弄了台虚拟机练手,承接上一篇博客(https://ww ...
- heartbeat 非联网安装(通过配置本地yum文件库安装heartbeat)
软件环境:centos6.5 一.下载rpm包 首先找一台联网的centos6.5机器 安装epel扩展源: yum install -y epel-release 安装yum-plugin-down ...
- spring cloud 初体验
spring cloud分为注册端.客户端以及消费端 初体验的理解就是: 注册端就是将之前所有的应用在这边进行注册,然后给每个应用都生成自己的标识,这些应用就是来自于客户端,消费端则通过调用注册端(有 ...
- Crashing Robots(水题,模拟)
1020: Crashing Robots 时间限制(普通/Java):1000MS/10000MS 内存限制:65536KByte 总提交: 207 测试通过:101 ...
- 通过java代码往mysql数据库中写入日期相关数据少13个小时
通过show variables like '%time_zone%'; 查看时区: CST 时区 名为 CST 的时区是一个很混乱的时区,有四种含义: 美国中部时间 Central Standard ...
- shell for 循环
test.sh #!/bin/bash for str in "C语言" "http://www.bilibili.com" "成立7年了" ...
- 用 jupyter notebook 打开 oui.txt 文件出现的问题及解决方案
问题背景:下载了2018 IEEE 最新的 oui.txt 文件.里面包含了 设备 MAC 地址的前六位对应的厂商.要做的工作是,将海量设备的 MAC 地址与 oui.txt 文件的信息比对,统计出 ...