怎么说呢,照着打一遍就自然理解了,再打一遍就会背了,再打一遍就会推了。

 // luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
const int maxn=3E5+;
int fa[maxn],son[maxn][],val[maxn],ans[maxn],n,m,opt,x,y,z;
bool tag[maxn];
bool notroot(int x){return son[fa[x]][]==x||son[fa[x]][]==x;}
void update(int x){ans[x]=ans[son[x][]]^ans[son[x][]]^val[x];}
void pushr(int x)
{
swap(son[x][],son[x][]);
tag[x]^=;
}
void pushdown(int x)
{
if(tag[x])
{
if(son[x][])pushr(son[x][]);
if(son[x][])pushr(son[x][]);
tag[x]=;
}
}
void rotate(int x,int c)
{
int y=fa[x];
fa[x]=fa[y];
son[y][!c]=son[x][c];
if(son[x][c])fa[son[x][c]]=y;
if(notroot(y)&&son[fa[y]][]==y)son[fa[y]][]=x;
else if(notroot(y))son[fa[y]][]=x;
son[x][c]=y;
fa[y]=x;
update(y);
update(x);
}
void down(int x)
{
if(!notroot(x)){pushdown(x);return;}
down(fa[x]);
pushdown(x);
}
void splay(int x)
{
down(x);
while(true)
{
int y=fa[x];
if(!notroot(x))break;
if(!notroot(y))
{
if(son[y][]==x)rotate(x,);
else rotate(x,);
break;
}
if(son[fa[y]][]==y)
{
if(son[y][]==x)rotate(y,),rotate(x,);
else rotate(x,),rotate(x,);
}
else
{
if(son[y][]==x)rotate(y,),rotate(x,);
else rotate(x,),rotate(x,);
}
}
}
void access(int x)
{
for(int y=;x;y=x,x=fa[x])
splay(x),son[x][]=y,update(x);
}
void makeroot(int x)
{
access(x);
splay(x);
pushr(x);
}
int findroot(int x)
{
access(x);
splay(x);
while(son[x][])pushdown(x),x=son[x][];
splay(x);
return x;
}
void split(int x,int y)
{
makeroot(x);
access(y);
splay(y);
}
void link(int x,int y)
{
makeroot(x);
if(findroot(y)!=x)fa[x]=y;
}
void cut(int x,int y)
{
makeroot(x);
if(findroot(y)==x&&fa[y]==x&&!son[y][])
{
fa[y]=son[x][]=;
update(x);
update(y);
}
}
int main()
{
ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=;i<=n;++i)cin>>val[i];
while(m--)
{
cin>>opt>>x>>y;
if(opt==)
{
split(x,y);
cout<<ans[y]<<endl;
}
else if(opt==)link(x,y);
else if(opt==)cut(x,y);
else
{
splay(x);
val[x]=y;
}
}
return ;
}

最新文章

  1. 开源项目GitHub
  2. 识别 Linux上的设备(磁盘)类型
  3. 一行代码解决各种IE兼容问题,IE6,IE7,IE8,IE9,IE10 http://www.jb51.net/css/383986.html
  4. .net Framework Class Library(FCL)
  5. psutil 是因为该包能提升 memory_profiler 的性能
  6. Volley框架之网络请求和图片加载
  7. Package inputenc Error: Unicode char \u8: not set up for use with LaTeX.
  8. Hadoop学习笔记(1)
  9. 嵌入式 hi3518c下ramdisk文件系统与文件系统烧写以及uboot中change-the-env
  10. 【Android】数据库的简单应用——增删改查的操作
  11. Linux系统挂载点与分区的关系(转载)
  12. iOS开发 masonry 设置tableHeadView
  13. document.getElementsByClassName在ie8及其以下浏览器的兼容性问题
  14. SQL SERVER 根据地图经纬度计算距离函数
  15. C# 用户控件之温度计
  16. numpy(四)
  17. Aforge.net识别简易数字验证码问题
  18. Curl测试socks5 or http 代理命令
  19. GPA简介
  20. Coursera Deep Learning 3 Structuring Machine Learning Projects, ML Strategy

热门文章

  1. JDBC——Java语言连接数据库的标准
  2. 初涉wheel 组
  3. 利用matplotlib库和numpy库画数学图形
  4. 【HNOI 2017】影魔
  5. Ubuntu下的Selenium爬虫的配置
  6. Win10外包公司(长年承接Win10App外包、Win10通用应用外包)
  7. mac 安装2019Adobe全家桶
  8. c++_day5_成员指针
  9. 在线批量将gps经纬度坐标转换为百度经纬度坐标
  10. 射频(SX1278)