原来的代码有一些问题。

主要是对于不一定存在的边如何去判断,首先要保证在一个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. VS2010编译错误:fatal error C1189: #error : This file requires _WIN32_WINNT to be #defined at least to 0x

    下面是彻底解决方法:在工程的stdafx.h中添加(如有类似语句,需注释掉)#ifndef WINVER // Allow use of features specific to Windows 95 ...

  2. 并发和多线程(三)--并发容器J.U.C和lock简介

    AQS: 是AbstractQueuedSynchronizer的简称,JUC的核心 底层是sync queue双向链表,还可能有condition queue单向链表,使用Node实现FIFO队列, ...

  3. Ubuntu搭建LAMP开发环境

    1.安装Apache sudo apt-get install apache2 测试: 浏览器访问 (如:http://localhost),出现It Works!网页. 查看状态: service ...

  4. js中=,==,===的区别

    =      赋值 ==    先判断类型,在判断值,可以做类型转换 ===  恒等判断

  5. php第二十二节课

    AJAX <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 ...

  6. Extjs定时操作

    查看api可知: // 启动一个简单的时钟任务,每秒执行一次更新一个 div var task = { run: function(){ Ext.fly('clock').update(new Dat ...

  7. [Luogu] P1407 [国家集训队]稳定婚姻

    题目描述 我国的离婚率连续7年上升,今年的头两季,平均每天有近5000对夫妇离婚,大城市的离婚率上升最快,有研究婚姻问题的专家认为,是与简化离婚手续有关. 25岁的姗姗和男友谈恋爱半年就结婚,结婚不到 ...

  8. manacher(马拉车)算法

    断断续续地看了两天的马拉车算法,可算是给搞明白了(贼开心),这算是自己搞懂的第一个算法了(23333333333333)这个算法照目前自己的理解来看,貌似就只能求个字符串中的回文串(接触这个算法是要求 ...

  9. CentOS \Linux文件权限详解

    文件和目录权限概述 在linux中的每一个文件或目录都包含有访问权限,这些访问权限决定了谁能访问和如何访问这些文件和目录. 通过设定权限可以从以下三种访问方式限制访问权限:只允许用户自己访问:允许一个 ...

  10. linux命令 info

    info命令是Linux下info格式的帮助指令. 就内容来说,info页面比man page编写得要更好.更容易理解,也更友好,但man page使用起来确实要更容易得多.一个man page只有一 ...