BZOJ_3282_Tree_LCT
BZOJ_3282_Tree_LCT
Description
Input
Output
对于每一个0号操作,你须输出X到Y的路径上点权的Xor和。
Sample Input
1
2
3
1 1 2
0 1 2
0 1 1
Sample Output
1
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define N 300050
#define ls ch[p][0]
#define rs ch[p][1]
#define get(x) (ch[f[x]][1]==x)
int ch[N][2],f[N],sum[N],n,m,val[N],rev[N];
inline bool isrt(int p) {
return ch[f[p]][1]!=p&&ch[f[p]][0]!=p;
}
inline void pushdown(int p) {
if(rev[p]) {
swap(ch[ls][0],ch[ls][1]);
swap(ch[rs][0],ch[rs][1]);
rev[ls]^=1; rev[rs]^=1;
rev[p]=0;
}
}
inline void pushup(int p) {
sum[p]=sum[ls]^sum[rs]^val[p];
}
inline void update(int p) {
if(!isrt(p)) update(f[p]);
pushdown(p);
}
void rotate(int x) {
int y=f[x],z=f[y],k=get(x);
if(!isrt(y)) ch[z][ch[z][1]==y]=x;
ch[y][k]=ch[x][!k]; f[ch[y][k]]=y;
ch[x][!k]=y; f[y]=x; f[x]=z;
pushup(y); pushup(x);
}
void splay(int x) {
update(x);
for(int fa;fa=f[x],!isrt(x);rotate(x))
if(!isrt(fa))
rotate(get(fa)==get(x)?fa:x);
}
void access(int p) {
int t=0;
while(p) splay(p),rs=t,pushup(p),t=p,p=f[p];
}
void makeroot(int p) {
access(p); splay(p);
swap(ls,rs); rev[p]^=1;
}
void link(int x,int p) {
makeroot(x); f[x]=p;
}
void cut(int x,int p) {
makeroot(x); access(p); splay(p); ls=f[x]=0;
}
int find(int p) {
access(p); splay(p);
while(ls) pushdown(p),p=ls;
return p;
}
void fix(int x,int v) {
/*access(x);*/ splay(x); sum[x]^=val[x]; val[x]=v; sum[x]^=val[x];
}
int main() {
scanf("%d%d",&n,&m);
int i,x,y,opt;
for(i=1;i<=n;i++) scanf("%d",&val[i]);
for(i=1;i<=m;i++) {
scanf("%d%d%d",&opt,&x,&y);
if(opt==0) {
makeroot(x); access(y); splay(y);
printf("%d\n",sum[y]);
}else if(opt==1) {
int t1=find(x),t2=find(y);
if(t1!=t2) link(x,y);
}else if(opt==2) {
int t1=find(x),t2=find(y);
if(t1==t2) cut(x,y);
}else {
fix(x,y);
}
}
}
BZOJ_3282_Tree_LCT的更多相关文章
随机推荐
- 80端口被NT kernel & System 占用
新年后正常上班的第一天,客户报告,虚拟机上的网站起不来了. 登录虚拟机的远程桌面,闪几下连接信息,后面就没了,不显示远程桌面.联系虚拟机管理,重启,远程桌面是连上了,网站还是起不来. 查看window ...
- windows SSH Tunnel实施日记
1.准备条件:SSH跳板服务器一个.软件:Putty,CCProxy 2.putty建立SSH Tunnel:先在session那儿把服务器地址填好,到Tunnel界面上,选Dynamics和Auto ...
- Node笔记四
异步操作 -Node采用chrome v8 引擎处理javascript脚本 --v8最大特点就是单线程运行,一次只能运行一个任务 -Node大量采用异步操作 --任务不是马上执行,而是插在任务队列的 ...
- FastDFS单机版安装
FastDFS 分布式文件系统 1 目标 了解项目中使用FastDFS的原因和意义. 掌握FastDFS的架构组成部分,能说出tracker和storage的作用. 了解FastDFS+nginx上传 ...
- Rabbit MQ 延迟插件rabbitmq_delayed_message_exchange的使用
环境: windows server 2008 R2 rabbitmq 3.7.2 下载插件: http://www.rabbitmq.com/community-plugins.html 注意要下载 ...
- Python和Java的硬盘夜话
这是一个程序员的电脑硬盘,在一个叫做"学习"的目录下曾经生活着两个小程序,一个叫做Hello.java,即Java小子:另外一个叫做hello.c ,也就是C老头儿. C老头儿的命 ...
- linux查看系统的日志------健康检查特性
last https://www.cnblogs.com/anruy/articles/5541675.html Nginx反向代理,健康状态检测,过载保护及配置文件详 ...
- python selenium鼠标键盘操作(ActionChains)
用selenium做自动化,有时候会遇到需要模拟鼠标操作才能进行的情况,比如单击.双击.点击鼠标右键.拖拽等等.而selenium给我们提供了一个类来处理这类事件--ActionChains sele ...
- redis Web服务器
redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorted set ...
- Switch在swift中的使用
switch的简单使用: 相比 C 和 objective - C 中的 switch 语句,Swift 中的 switch 语句不会默认的掉落到每个 case 的下面进入 另一个 case.相反,第 ...