题目

终于去写\(LCT\)了

这个大爷讲的挺好的

板子

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#define maxn 300005
#define re register
#define LL long long
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
inline int read()
{
char c=getchar();int x=0;while(c<'0'||c>'9') c=getchar();
while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-48,c=getchar();return x;
}
int n,m;
int fa[maxn],v[maxn],s[maxn],ch[maxn][2],st[maxn],rev[maxn];
inline int nroot(int x) {return ch[fa[x]][0]==x||ch[fa[x]][1]==x;}
inline void pushup(int x) {s[x]=s[ch[x][0]]^s[ch[x][1]]^v[x];}
inline void pushdown(int x) {
if(!rev[x]) return;
rev[x]=0,rev[ch[x][0]]^=1,rev[ch[x][1]]^=1;
std::swap(ch[ch[x][0]][0],ch[ch[x][0]][1]);
std::swap(ch[ch[x][1]][0],ch[ch[x][1]][1]);
}
inline void rotate(int x) {
int y=fa[x],z=fa[y],k=ch[y][1]==x,w=ch[x][k^1];
if(nroot(y)) ch[z][ch[z][1]==y]=x;
ch[x][k^1]=y,ch[y][k]=w;
pushup(y),pushup(x);fa[w]=y;fa[y]=x,fa[x]=z;
}
inline void splay(int x) {
int y=x,top=0;
st[++top]=x;
while(nroot(y)) st[++top]=fa[y],y=fa[y];
while(top) pushdown(st[top--]);
while(nroot(x)) {
int y=fa[x];
if(nroot(y)) rotate((ch[y][1]==x)^(ch[fa[y]][1]==y)?x:y);
rotate(x);
}
}
inline void access(int x) {
for(re int y=0;x;y=x,x=fa[x])
splay(x),ch[x][1]=y,pushup(x);
}
inline void makeroot(int x) {
access(x);splay(x);rev[x]^=1;std::swap(ch[x][0],ch[x][1]);
}
inline int findroot(int x) {
access(x);splay(x);
while(ch[x][0]) pushdown(x),x=ch[x][0];
splay(x);return x;
}
inline void split(int x,int y) {
makeroot(x);access(y);splay(y);
}
inline void link(int x,int y) {
makeroot(x);
if(findroot(y)!=x)fa[x]=y;
}
inline void cut(int x,int y) {
makeroot(x);
if(findroot(y)==x&&fa[y]==x&&!ch[y][0]) ch[x][0]=fa[y]=0,pushup(x);
}
int main()
{
n=read(),m=read();
for(re int i=1;i<=n;i++) v[i]=read();
int opt,x,y;
while(m--) {
opt=read(),x=read(),y=read();
if(opt==0) split(x,y),printf("%d\n",s[y]);
if(opt==1) link(x,y);
if(opt==2) cut(x,y);
if(opt==3) splay(x),v[x]=y,pushup(x);
}
return 0;
}

最新文章

  1. Java程序员应该掌握的10项技能
  2. js中的hasOwnProperty和isPrototypeOf方法
  3. Java--剑指offer(6)
  4. 七牛CEO许式伟:移动游戏资源存贮的大趋势
  5. UVa 11624,两次BFS
  6. Memcache应用场景介绍,说明
  7. 【POJ 1741】 Tree (树的点分治)
  8. Android上按钮解决快速点击问题
  9. Java实现Linux下服务器程序的双守护进程
  10. Linux SD/MMC/SDIO驱动分析
  11. ssm+easyUI datagrid 不能显示后台controller层返回的json数据
  12. webapp在Android中点击链接的时候会有淡蓝色的遮罩层
  13. Pycharm直接连接Github
  14. Node.js 蚕食计划(五)—— Koa 基础项目搭建
  15. python下实现二叉堆以及堆排序
  16. java 文件目录树
  17. 【react】---手动封装一个简易版的redux
  18. 使用OkHttp和Retrofit发送网易云信验证码
  19. shell编程-test命令(七)
  20. abp xunit Can not register IHostingEnvironment. It should be a non-abstract class. If not, it should be registered before.”

热门文章

  1. oracle 操作实例(一)----redolog 损坏恢复
  2. shell 脚本学习之内部变量
  3. 转载:.NET Memory Leak: XmlSerializing your way to a Memory Leak
  4. Linux 连接 Xshell 及网络配置
  5. Bash 终端快捷键
  6. java线程安全问题原理性分析
  7. win10下clodeblocks编译C语言乱码
  8. Eclipse Startup
  9. Android Activity中状态保存机制
  10. 【Linux】Linux 找回Root用户密码