原来的代码有一些问题。

主要是对于不一定存在的边如何去判断,首先要保证在一个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. C++算法库学习__std::sort__对 vector进行排序_排序后就可以进行使用std::lower_bound进行二分查找(查找第一个大于等于指定值的迭代器的位置)__std::unique

    std::sort      对vector成员进行排序; std::sort(v.begin(),v.end(),compare);   std::lower_bound 在排序的vector中进行 ...

  2. vue基础---介绍

    (1)声明式渲染 Vue.js 的核心是采用简洁的模板语法来声明式地将数据渲染进 DOM 的系统: ①文本 <div id="app"> {{ message }} & ...

  3. 链表相关的leetcode重要题目

    Leetcode 92:反转链表II 解决这道题需要三个步骤: 找到需要反转的第一个节点.可以通过头节点前进m-1步,找到反转开始的位置. 将需要反转的部分进行反转.参考Leetcode 206:反转 ...

  4. git学习(3)----git 新建分支并提交本地代码到远程分支

    一.步骤 1.在gitlab上创建一个issue,issue一般来说是版本发布说明.比如本次更新了什么功能,修复了什么bug什么的. 2.然后在本地创建一个branch,或者直接在gitlab上申请m ...

  5. Linux kernel-汇编基础

    mov ASSEMABLE C LANGUAGE movl %eax,%edx edx = eax; --->register mode movl $0x123,%edx edx = 0x123 ...

  6. P2041 分裂游戏

    P2041 分裂游戏 手推$n=3$是无解的,推断$n>=3$是无解的 证明略,这是道结论题. #include<iostream> #include<cstdio> # ...

  7. I Think I Need a Houseboat POJ - 1005(数学)

    题目大意 在二维坐标内选定一个点,问你当洪水以半圆形扩散且每年扩散50单位,哪一年这个点被被洪水侵蚀? 解法 代码 #include <iostream> #include <cst ...

  8. SQLAlchemy-Utils

    由于sqlalchemy中没有提供choice方法,所以借助SQLAlchemy-Utils组件提供的choice方法. 安装: pip3 install sqlalchemy_utils 示例: f ...

  9. idea搭建maven项目 【转发】

    为了创建maven项目可是花了我时间了,网上的教程跟我的实际情况不符合,尤其是facets .artifacts 那块.幸亏找到这篇文章没解决了我的问题,他的描述跟我的情况一模一样.这篇文章竟然来自百 ...

  10. 转一篇GCC相关的文章

    http://blog.csdn.net/dadoneo/article/details/8201403 Glibc辅助运行库 (C RunTime Library): crt0.o,crt1.o,c ...