原来的代码有一些问题。

主要是对于不一定存在的边如何去判断,首先要保证在一个splay里,然后保证彼此之间直接联通且x的右儿子是空的

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define ll long long
#define inf 2139062143
#define MAXN 300100
#define MOD 998244353
#define rep(i,s,t) for(register int i=(s),i##__end=(t);i<=i##__end;++i)
#define dwn(i,s,t) for(register int i=(s),i##__end=(t);i>=i##__end;--i)
#define ren for(register int i=fst[x];i;i=nxt[i])
#define pb(i,x) vec[i].push_back(x)
#define pls(a,b) (a+b)%MOD
#define mns(a,b) (a-b+MOD)%MOD
#define mul(a,b) (1LL*(a)*(b))%MOD
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') f=-;ch=getchar();}
while(isdigit(ch)) {x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m;
int ch[MAXN][],tag[MAXN],sum[MAXN],val[MAXN],fa[MAXN];
struct Lct
{
int which(int x) {return ch[fa[x]][]==x;}
int isroot(int x) {return ch[fa[x]][]!=x&&ch[fa[x]][]!=x;}
void upd(int x) {sum[x]=val[x]^sum[ch[x][]]^sum[ch[x][]];}
void rev(int x) {tag[x]^=;swap(ch[x][],ch[x][]);}
void pshd(int x)
{
if(!tag[x]) return ;tag[x]^=;
if(ch[x][]) rev(ch[x][]);
if(ch[x][]) rev(ch[x][]);
}
void rotate(int x)
{
int f=fa[x],ff=fa[f],k=which(x);
if(!isroot(f)) ch[ff][ch[ff][]==f]=x;fa[x]=ff;
ch[f][k]=ch[x][k^],fa[ch[f][k]]=f,ch[x][k^]=f,fa[f]=x;
upd(f);upd(x);
}
int st[MAXN],top;
void splay(int x)
{
st[top=]=x;
for(int i=x;!isroot(i);i=fa[i]) st[++top]=fa[i];
dwn(i,top,) pshd(st[i]);
for(int f;!isroot(x);rotate(x))
if(!isroot(f=fa[x])) rotate(which(x)==which(f)?f:x);
}
void access(int x) {for(int t=;x;t=x,x=fa[x]){splay(x);ch[x][]=t;upd(x);}}
void mkrt(int x) {access(x);splay(x);rev(x);}
void link(int x,int y) {mkrt(x);fa[x]=y;}
void split(int x,int y) {mkrt(x);access(y);splay(y);}
int find(int x)
{
access(x);splay(x);
while(ch[x][]) pshd(x),x=ch[x][];return x;
}
void cut(int x,int y) {split(x,y);if(fa[x]==y&&ch[y][]==x&&!ch[x][]) ch[y][]=fa[x]=,upd(y);}
}lct;
int main()
{
n=read(),m=read();int t,a,b;rep(i,,n) val[i]=read();
while(m--)
{
t=read(),a=read(),b=read();
if(!t) {lct.split(a,b);printf("%d\n",sum[b]);}
if(t==&&lct.find(a)!=lct.find(b)) lct.link(a,b);
if(t==&&lct.find(a)==lct.find(b)) lct.cut(a,b);
if(t==) val[a]=b,splay(a);
}
}

luogu 3690 【模板】 Link Cut Tree (动态树)的更多相关文章

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

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

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

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

  3. Link Cut Tree 动态树 小结

    动态树有些类似 树链剖分+并查集 的思想,是用splay维护的 lct的根是动态的,"轻重链"也是动态的,所以并没有真正的轻重链 动态树的操作核心是把你要把 修改/询问/... 等 ...

  4. LCT(link cut tree) 动态树

    模板参考:https://blog.csdn.net/saramanda/article/details/55253627 综合各位大大博客后整理的模板: #include<iostream&g ...

  5. 洛谷P3690 Link Cut Tree (动态树)

    干脆整个LCT模板吧. 缺个链上修改和子树操作,链上修改的话join(u,v)然后把v splay到树根再打个标记就好. 至于子树操作...以后有空的话再学(咕咕咕警告) #include<bi ...

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. Apache Maven 3.0.3 (yum) 安裝 (CentOS 6.4 x64)

    介紹http://maven.apache.org/ Maven是一個專案的開發,管理和綜合工具. 下載http://maven.apache.org/download.cgi 參考http://ma ...

  2. Java基础(三)--final关键字

    final通常是指"不可改变的",例如我们使用的常量 通常可以有三种使用情况: 一.final修饰数据 如果final修饰数据,也就是通常所说的常量,从字面上看,常量就是不能修改的 ...

  3. HDU多校Round 4

    Solved:3 rank:405................................. B. Harvest of Apples 知道了S(n,m) 可以o(1)的求S(n - 1, m ...

  4. 网络编程 - 简单的socket例子

    1.客户端 #客户端import socketclient=socket.socket() #生成socket连接对象client.connect(("localhost",696 ...

  5. [angular2]解决安装 angular-cli 报错:Cannot find module 'github-url-from-git'

    1.运行:sudo rm -rf /usr/local/lib/node_modules/npm 2.重新安装最新版本的node,最新版本的node已经集成了npm,所以无需另外安装. 3.运行:su ...

  6. 安装charles

    简介: Charles主要的功能包括: 支持SSL代理.可以截取分析SSL的请求. 支持流量控制.可以模拟慢速网络以及等待时间(latency)较长的请求. 支持AJAX调试.可以自动将json或xm ...

  7. 洛谷 1823 [COI2007] Patrik 音乐会的等待

    [题解] 维护一个单调栈即可. 但是因为有相同身高的存在,所以要稍微考虑下相同身高的处理.因为这个卡了一下下QAQ... #include<cstdio> #include<algo ...

  8. [luoguP1111] 修复公路(并查集)

    传送门 呵呵的最小生成树 ——代码 #include <cstdio> #include <iostream> #include <algorithm> #defi ...

  9. nyoj_68_三点顺序_201404152013

    三点顺序 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 现在给你不共线的三个点A,B,C的坐标,它们一定能组成一个三角形,现在让你判断A,B,C是顺时针给出的还是逆 ...

  10. [bzoj1115][POI2009]石子游戏Kam_博弈论_阶梯博弈

    石子游戏 Kam bzoj-1115 POI-2009 题目大意:给定n堆石子,两个人轮流取石子.每堆石子的个数都不少于前一堆石子.每次取后也必须维持这个性质.问谁有必胜策略. 注释:$1\le ca ...