勉强算是结了个大坑吧或者才开始

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); (a) <= (c); ++(a))
#define nR(a,b,c) for(register int a = (b); (a) >= (c); --(a))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Swap(a,b) ((a) ^= (b) ^= (a) ^= (b))
#define ll long long
#define u32 unsigned int
#define u64 unsigned long long #define ON_DEBUGG #ifdef ON_DEBUGG #define D_e_Line printf("\n----------\n")
#define D_e(x) cout << (#x) << " : " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("in.txt", "r", stdin)
#define FileSave() freopen("out.txt", "w", stdout)
#include <ctime>
#define TIME() fprintf(stderr, "\ntime: %.3fms\n", clock() * 1000.0 / CLOCKS_PER_SEC) #else #define D_e_Line ;
#define D_e(x) ;
#define Pause() ;
#define FileOpen() ;
#define FileSave() ;
#define TIME() ;
//char buf[1 << 21], *p1 = buf, *p2 = buf;
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++) #endif using namespace std;
struct ios{
template<typename ATP>inline ios& operator >> (ATP &x){
x = 0; int f = 1; char ch;
for(ch = getchar(); ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
while(ch >= '0' && ch <= '9') x = x * 10 + (ch ^ '0'), ch = getchar();
x *= f;
return *this;
}
}io; template<typename ATP>inline ATP Max(ATP a, ATP b){
return a > b ? a : b;
}
template<typename ATP>inline ATP Min(ATP a, ATP b){
return a < b ? a : b;
}
template<typename ATP>inline ATP Abs(ATP a){
return a < 0 ? -a : a;
} const int N = 300007; struct node {
int ch[2], fa, val, sum;
bool rev;
}t[N];
#define ls t[u].ch[0]
#define rs t[u].ch[1] inline bool Ident(int u) {
return t[t[u].fa].ch[1] == u;
} inline bool IsRoot(int u) {
return t[t[u].fa].ch[0] != u && t[t[u].fa].ch[1] != u;
} inline void Pushup(int u) {
t[u].sum = t[u].val ^ t[ls].sum ^ t[rs].sum;
} inline void Pushrev(int u) {
Swap(t[u].ch[0], t[u].ch[1]);
t[u].rev ^= 1;
} inline void Pushdown(int u) {
if(!t[u].rev) return;
if(t[u].ch[0]) Pushrev(t[u].ch[0]);
if(t[u].ch[1]) Pushrev(t[u].ch[1]);
t[u].rev = 0;
} int sta[N], top; inline void Rotate(int x) {
int y = t[x].fa, z = t[y].fa, k = Ident(x);
t[x].fa = z; if(!IsRoot(y)) t[z].ch[Ident(y)] = x;
t[y].ch[k] = t[x].ch[k ^ 1], t[t[x].ch[k ^ 1]].fa = y;
t[x].ch[k ^ 1] = y, t[y].fa = x;
Pushup(y), Pushup(x);
} inline void Splay(int u) {
int x = u;
top = 0;
while(!IsRoot(u)) {
sta[++top] = u;
u = t[u].fa;
}
sta[++top] = u;
nR(i,top,1){
Pushdown(sta[i]);
}
while(!IsRoot(x)) {
int y = t[x].fa;
if(!IsRoot(y)){
Ident(x) == Ident(y) ? Rotate(y) : Rotate(x);
}
Rotate(x);
}
Pushup(x);
} inline void Access(int u) {
for(int v = 0; u; v = u, u = t[u].fa){
Splay(u);
t[u].ch[1] = v;
Pushup(u);
}
} inline void MakeRoot(int u) {
Access(u);
Splay(u);
Pushrev(u);
} inline int FindRoot(int u) {
Access(u);
Splay(u);
while(ls) u = ls;
Splay(u);
return u;
} inline void Split(int u, int v) {
MakeRoot(u);
Access(v);
Splay(v);
} inline void Link(int u, int v) {
Split(u, v);
t[u].fa = v;
} inline void Cut(int u, int v){
MakeRoot(u);
if(FindRoot(v) == u && t[v].fa == u && !t[v].ch[0]){
t[v].fa = t[u].ch[1] = 0;
Pushup(u);
}
} inline void Modify(int u, int w) {
// Access(u);
Splay(u);
t[u].val = w;
Pushup(u);
} int main() {
//FileOpen();
//FileSave();
int n, m;
io >> n >> m;
R(i,1,n){
io >> t[i].val;
t[i].sum = t[i].val;
}
while(m--){
int opt, x, y;
io >> opt >> x >> y;
switch(opt){
case 0:
Split(x, y);
printf("%d\n", t[y].sum);
break;
case 1:
Link(x, y);
break;
case 2:
Cut(x, y);
break;
case 3:
Modify(x, y);
break;
}
}
return 0;
}

LuoguP3690 【模板】Link Cut Tree (LCT)的更多相关文章

  1. 洛谷P3690 [模板] Link Cut Tree [LCT]

    题目传送门 Link Cut Tree 题目背景 动态树 题目描述 给定n个点以及每个点的权值,要你处理接下来的m个操作.操作有4种.操作从0到3编号.点从1到n编号. 0:后接两个整数(x,y),代 ...

  2. LCT总结——概念篇+洛谷P3690[模板]Link Cut Tree(动态树)(LCT,Splay)

    为了优化体验(其实是强迫症),蒟蒻把总结拆成了两篇,方便不同学习阶段的Dalao们切换. LCT总结--应用篇戳这里 概念.性质简述 首先介绍一下链剖分的概念(感谢laofu的讲课) 链剖分,是指一类 ...

  3. 模板Link Cut Tree (动态树)

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

  4. 洛谷.3690.[模板]Link Cut Tree(动态树)

    题目链接 LCT(良心总结) #include <cstdio> #include <cctype> #include <algorithm> #define gc ...

  5. BZOJ 3282 Link Cut Tree (LCT)

    题目大意:维护一个森林,支持边的断,连,修改某个点的权值,求树链所有点点权的异或和 洛谷P3690传送门 搞了一个下午终于明白了LCT的原理 #include <cstdio> #incl ...

  6. 【刷题】洛谷 P3690 【模板】Link Cut Tree (动态树)

    题目背景 动态树 题目描述 给定n个点以及每个点的权值,要你处理接下来的m个操作.操作有4种.操作从0到3编号.点从1到n编号. 0:后接两个整数(x,y),代表询问从x到y的路径上的点的权值的xor ...

  7. Luogu 3690 Link Cut Tree

    Luogu 3690 Link Cut Tree \(LCT\) 模板题.可以参考讲解和这份码风(个人认为)良好的代码. 注意用 \(set\) 来维护实际图中两点是否有直接连边,否则无脑 \(Lin ...

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

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

  9. P3690 【模板】Link Cut Tree (动态树)

    P3690 [模板]Link Cut Tree (动态树) 认父不认子的lct 注意:不 要 把 $fa[x]$和$nrt(x)$ 混 在 一 起 ! #include<cstdio> v ...

  10. LG3690 【模板】Link Cut Tree (动态树)

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

随机推荐

  1. 安装Siege到Linux(源码)

    运行环境 系统版本:CentOS Linux release 7.3.1611 (Core) 软件版本:siege-4.0.4 硬件要求:无 安装过程 1.安装依赖 [root@localhost ~ ...

  2. Johnson 全源最短路

    学这个是为了支持在带负权值的图上跑 Dijkstra. 为了这个我们要考虑把负的权值搞正. 那么先把我们先人已经得到的结论摆出来.我们考虑先用 SPFA 对着一个满足三角形不等式的图跑一次最短路,具体 ...

  3. 二叉树遍历在Unity中的实现

    前言:今天放一天,想到要放国庆假了就心烦气躁,躺床上又焦虑,回想起面试官的一副扑克脸,马上跳起来看了看数据结构. 今天复习了二叉树,包括一些基本概念和特性,当看到二叉树遍历的章节时,马上联想到了Uni ...

  4. 我熬夜读完这份“高分宝典”,竟4面拿下字节跳动offer

    前言 怎样的契机? 实际上,目前毕业已经两年时间了,在大学时就已经开始关注字节跳动的发展.一开始,我是电气自动化专业的,大二清楚目标之后就转计算机了,大四进了一家小型的互联网公司实习,具体就不说哪家了 ...

  5. flink窗口分类

    窗口分类 按照驱动类型分类 窗口本身是截取有界数据的一种方式,所以窗口一个非常重要的信息就是"怎样截取数据".换句话说,就是以什么标准来开发和结束数据的截取. 按照驱动类型分类主要 ...

  6. tensorflow版本的bert模型 GPU的占用率为100%而其利用率为0%

    Notice: 本方法只是解决问题的一种可能,不一定百分百适用,出现这个问题还有很多其他原因,这个可以作为解决的一种尝试!!! 经过检查发现,是由于激活环境的原因 使用 conda activate ...

  7. SAP 文件操作类 CL_GUI_FRONTEND_SERVICES

    1 .文件下载. DATA: l_filename TYPE string, "file name l_path TYPE string, "file path l_fullpat ...

  8. Java中时间方法大全01(持续更新)

    下面这些方法都可以封装到一个工具类中 /** * 获取当前时间的时间戳 */ public static int getCurrentTimeIntValue() { return (int) (Sy ...

  9. 解决github.com 的响应时间过长以及hosts配置不能保存的问题

    github.com 的响应时间过长 1 获取github可以使用的DNS域名 DNS查询 选择TTL值最小的 2 修改hosts配置 打开之后在最后加上如下内容,保存即可 3 出现hosts不能保存 ...

  10. CesiumJS 2022^ 源码解读[6] - 三维模型(ModelExperimental)新架构

    目录 1. ModelExperimental 的缓存机制 1.1. 缓存池 ResourceCache 1.2. 缓存对象的键设计 ResourceCacheKey 2. 三维模型的加载与解析 2. ...