#include<cstdio>
#include<algorithm>
#define N 500010
#define rg register
#define ls (c[u][0])
#define rs (c[u][1])
using namespace std;
int n,m,x,y,opt,top,val[N],c[N][],fa[N],xr[N],st[N],rev[N];
inline int read(){
int k=,f=; char c=getchar();
while(c<''||c>'')c=='-'&&(f=-),c=getchar();
while(''<=c&&c<='')k=k*+c-'',c=getchar();
return k*f;
}
inline bool isroot(int u){
return c[fa[u]][]!=u&&c[fa[u]][]!=u;
}
inline bool which(int u){
return c[fa[u]][]==u;
}
inline void pushup(int u){
xr[u]=xr[ls]^xr[rs]^val[u];
}
inline void pushdown(int u){
rev[ls]^=; rev[rs]^=; rev[u]=; swap(ls,rs);
}
void rotate(int u){
int f=fa[u],gf=fa[f],wh=which(u);
if(!isroot(f)) c[gf][which(f)]=u;
fa[u]=gf; fa[f]=u; fa[c[u][wh^]]=f;
c[f][wh]=c[u][wh^]; c[u][wh^]=f;
pushup(f); pushup(u);
}
void splay(int u){
st[top=]=u;
for(rg int i=u;!isroot(i);i=fa[i]) st[++top]=fa[i];
for(rg int i=top;i;i--) if(rev[st[i]]) pushdown(st[i]);
while(!isroot(u)){
if(!isroot(fa[u])) rotate(which(u)==which(fa[u])?fa[u]:u);
rotate(u);
}
}
inline void access(int u){
for(rg int son=;u;son=u,u=fa[u]) splay(u),c[u][]=son,pushup(u);
}
inline void makeroot(int u){
access(u); splay(u); rev[u]^=;
}
int find(int u){
access(u); splay(u);
while(ls) u=ls; return u;
}
void split(int x,int y){
makeroot(x); access(y); splay(y);
}
void cut(int x,int y){
split(x,y); bool goright=;
int t=c[y][];
while(c[t][]) t=c[t][],goright=;
if(t==x&&goright) c[fa[t]][]=,fa[x]=;
if(t==x&&(!goright)) c[y][]=,fa[x]=;
}
void link(int x,int y){
makeroot(x); fa[x]=y;
}
int main(){
n=read(); m=read();
for(rg int i=;i<=n;i++) val[i]=xr[i]=read();
while(m--){
opt=read(); x=read(); y=read();
if(opt==) split(x,y),printf("%d\n",xr[y]);
if(opt==) if(find(x)!=find(y))link(x,y);
if(opt==) if(find(x)==find(y)) cut(x,y);
if(opt==) access(x),splay(x),val[x]=y,pushup(x);
}
return ;
}

【模板】Link-Cut Tree的更多相关文章

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

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

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

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

  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. 【刷题】洛谷 P3690 【模板】Link Cut Tree (动态树)

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

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

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

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

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

  8. AC日记——【模板】Link Cut Tree 洛谷 P3690

    [模板]Link Cut Tree 思路: LCT模板: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 30 ...

  9. LG3690 【模板】Link Cut Tree 和 SDOI2008 洞穴勘测

    UPD:更新了写法. [模板]Link Cut Tree 给定n个点以及每个点的权值,要你处理接下来的m个操作.操作有4种.操作从0到3编号.点从1到n编号. 后接两个整数(x,y),代表询问从x到y ...

  10. (RE) luogu P3690 【模板】Link Cut Tree

    二次联通门 : luogu P3690 [模板]Link Cut Tree 莫名RE第8个点....如果有dalao帮忙查错的话万分感激 #include <cstdio> #includ ...

随机推荐

  1. return在Java中的两个作用

    Java中return的两个作用:   (1)返回方法指定类型的值(这个值总是确定的),也可以是对象   (2)方法的结束

  2. 【SCOI 2011】 糖果

    [题目链接] 点击打开链接 [算法] 当x = 1时,连边(a,b,0)和(b,a,0) 当x = 2时,连边(a,b,1) 当x = 3时,连边(b,a,0) 当x = 4时,连边(b,a,1) 当 ...

  3. JAVA Swing 组件演示***

    下面是Swing组件的演示: package a_swing; import java.awt.BorderLayout; import java.awt.Color; import java.awt ...

  4. ubuntu 16.04 Hbase 安装

    1.解压安装包至路径 /usr/local 1.1.sudo tar -zxf ~/下载/hbase-1.1.2-bin.tar.gz -C /usr/local 2.将解压的文件名hbase-1.1 ...

  5. 编译android4.4 报错error: call to '__property_get_too_small_error' declared with attribute 的处理 (转载)

    转自:http://blog.csdn.net/syhost/article/details/14448899 完整的报错为: system/core/include/cutils/propertie ...

  6. css bug(ie6兼容问题)

    二.五大浏览器内核1.trident(MSHTML)(三叉戟:三叉线,三齿鱼叉) Gecko (壁虎) presto(迅速的) webkit(safari内核,Chrome内核原型,他是苹果公司自己的 ...

  7. AngularJS过滤器filter-保留小数-渲染页面-小数点-$filter

    AngularJS      保留小数 默认是保留3位 固定的套路是 {{deom | number:4}} 意思就是保留小数点 的后四位 在渲染页面的时候 加入这儿个代码 用来精确浮点数,指定小数点 ...

  8. centos安装 memcached

    .安装 yum -y update yum install -y libevent libevent-devel yum install -y memcached 2.配置 vi /etc/sysco ...

  9. [ CQOI 2009 ] 中位数图

    \(\\\) \(Description\) 给出\(N\)的一个全排列,统计该排列有多少个长度为奇数的连续子序列,中位数是\(B\). \(N\in [0,10^5]\),\(B\in [0,N]\ ...

  10. JavaScript入门笔记

    第一章 JavaScript语法 1.1 初识JavaScript 1.3 数据类型 1.4 string和boolean类型 1.5 算数操作符 第二章 JavaScript流程控制语句 2.1 循 ...