怎么说呢,照着打一遍就自然理解了,再打一遍就会背了,再打一遍就会推了。

 // 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模板(无讲解)的更多相关文章

  1. LCT模板

    之前一直用的LCT模板,因为其实个人对LCT和Splay不是很熟,所以用起来总觉得略略的坑爹,过了一段时间就忘了,但事实上很多裸的LCT要改的东西是不多的,所以今天写了些注释,以后可能套起模板来会得心 ...

  2. LCT 模板及套路总结

    这一个月貌似已经考了无数次\(LCT\)了..... 保险起见还是来一发总结吧..... A. LCT 模板 \(LCT\) 是由大名鼎鼎的 \(Tarjan\) 老爷发明的. 主要是用来维护树上路径 ...

  3. [洛谷P1501] [国家集训队]Tree II(LCT模板)

    传送门 这是一道LCT的板子题,说白了就是在LCT上支持线段树2的操作. 所以我只是来存一个板子,并不会讲什么(再说我也不会,只能误人子弟2333). 不过代码里的注释可以参考一下. Code #in ...

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

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

  5. Miller Robbin测试模板(无讲解)

    想着费马定理和二次探测定理就能随手推了. 做一次是log2n的. #include<bits/stdc++.h> using namespace std; typedef long lon ...

  6. NTT模板(无讲解)

    #include<bits/stdc++.h>//只是在虚数部分改了一下 using namespace std; typedef long long int ll; ; ; ; ; ll ...

  7. FFT模板(无讲解)

    #include<bits/stdc++.h> using namespace std; ; const double pi=3.1415926535898; ],len; struct ...

  8. Luogu 3690 LCT - 模板

    推荐几篇比较好的博客: FlashHu 的 讲解比较好 : 传送门 Candy 的 代码~ : 传送门 以及神犇Angel_Kitty的 学习笔记: 传送门 Code V 模板 #include< ...

  9. BZOJ3282: Tree (LCT模板)

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

随机推荐

  1. 使用QPlainText代替QText

    1.现象 在项目开发中,经常使用QText来显示解析的数据,比如从网络中获取到一个数据包,解析成中文加以显示,当时间过久或者字符串比较多的时候,就会产生一定的卡顿,所以需要限制QText的行数,或者清 ...

  2. 关于py的思考

    1.我希望py课程应该涉及到如何提高编程效率,因为已经c的编程基础,不是特别在意怎么用py,而是在意怎么用得更好 2.基本技能的话,掌握好各类基本函数的用法 3.理论课精讲,实验课独立操作,并把出现的 ...

  3. 连接MySQL报错The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone.

    MySQL time zone 时区错误 使用root用户登陆执行命令: ---> show variables like '%time_zone%'; 默认值system为美国时间:如下图: ...

  4. python实现列表去重的方法

    >>> l=[,,,,,,] >>> list(set(l)) [, , , ] >>>

  5. 基于三层架构项目下的Ado【六】

    一.基于三层架构项目下的Ado增删改查总结,提示:现在一般都是使用EF框架操作. 1. 先在model层创建出一个和你将会查询出一样类型的表,比如你将查询出的有五个字段,那么你就需要创建出一个和你查询 ...

  6. mint修改host

    sudo xed /etc/hosts # Pycharm 0.0.0.0 account.jetbrains.com0.0.0.0 www.jetbrains.com #sublime text3 ...

  7. win2008 401 - 未授权: 由于凭据无效,访问被拒绝。解决方法

    iiis中一个小配置的问题,“身份验证”里面“启用匿名身份验证”,编辑匿名身份验证凭据,选中下面的“应用程序池标识”  就可以了

  8. Lab 10-1

    This lab includes both a driver and an executable. You can run the executable from anywhere, but in ...

  9. Bubble sort of sorting algorithm

    Bubble sort,It's a relatively basic algorithm.The core implementation ideas are as follows: 1.Define ...

  10. 深入理解Plasma(四)Plasma Cash

    这一系列文章将围绕以太坊的二层扩容框架 Plasma,介绍其基本运行原理,具体操作细节,安全性讨论以及未来研究方向等.本篇文章主要介绍在 Plasma 框架下的项目 Plasma Cash. 在上一篇 ...