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

 // 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. 7步快速解决SQLServer数据库(2008版)重装问题

    最近遇到了鼠标双击启动不了数据库的问题,根据事件管理器和自己的最近的使用情况初步判断估计是自己在用360误伤了数据库(哭) 没有办法只好重新安装一下了,参考了网上的一些大神们的教程然后自己实战操作一下 ...

  2. web性能测试

    在公司Confluence上看到一篇好文,原链接已不能访问.先收藏 转帖自:http://blog.csdn.net/wxq8102/article/details/1735726 1.1基本概念并发 ...

  3. fcntl设置FD_CLOEXEC标志作用【转】

    本文转载自:https://blog.csdn.net/ustc_dylan/article/details/6930189 通过fcntl设置FD_CLOEXEC标志有什么用?close on ex ...

  4. C# 数组与集合的区别

    数组:声明数组的时候必须指定数组的长度.数组在内存中是连续的,索引速度很快,赋值和修改也很简单. 数组的容量是固定的,您只能一次获取或设置一个元素的值,而ArrayList或List的容量可根据需要自 ...

  5. 安装Office2016遇到“无法流式传输Office”问题

    安装Office2016遇到“无法流式传输Office”问题,请问如何解决 很抱歉,找不到所需的文件,请检查安装源是否可访问,然后再试. 错误代码:30068-39(2) ============== ...

  6. Swagger和Postman的配置和使用

    Swagger 1. 配置 pom文件添加swagger依赖,注意版本,2.8.0可以使用 <dependency> <groupId>io.springfox</gro ...

  7. buaacoding_2018算法期末上机G题.地铁建设题解

    // 标注:本文旨在为博主确立一种题解的基本范式,以避免博主的题解流于AC代码的粘贴.此基本范式为:完整而简洁明了的思路及其推导说明,力图触及问题的本质并衍生对同类问题的思路分析,使得题解具有泛用性, ...

  8. flask-login模块

    flask-login为flask提供了用户会话管理.他处理了日常的登入,登出并且长时间记住用户的会话. 1.在会话中存储当前活跃的用户ID,让你能够自由地登入和登出. 2.让你限制登入或登出用户可以 ...

  9. vue-cli 最强指南

    今天在这篇文章里,会对 vue-cli 的功能做个详细的整理,把 vue-cli 所有的功能都列出来.注:这个是官网连接:https://cli.vuejs.org/zh/guide/ ,建议多看细看 ...

  10. Lintcode93-Balanced Binary Tree-Easy

    93. Balanced Binary Tree Given a binary tree, determine if it is height-balanced. For this problem, ...