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的更多相关文章
随机推荐
- Java内存模型_重排序
重排序:是指编译器和处理器为了优化程序性能而对指令序列进行重新排序的一种手段 1..编译器优化的重排序.编译器在不改变单线程程序语义的前提下,可以重新安排语句的执行顺序. 2..指令级并行的重排序.现 ...
- 安装centOS后要解决的问题
1,检查是否联网 ping www.baidu.com 未显示: 则表示网络未连接 首先关闭防火墙 sudo systemctl stop firewalld.service #停止firewall ...
- django-debug-toolbar的配置以及使用
django-debug-toolbar django,web开中,用django-debug-toolbar来调试请求的接口,无疑是完美至极. 可能本人,见识博浅,才说完美至极, 大神,表喷,抱 ...
- ssh优缺点
面试归来 技术面试官叫我谈谈 ssh优缺点 平时用起来倒是挺顺手..但是从来没有系统的总结过..导致很多点会都没有说出来.. 这次我认真总结了一下... 常说的好处 开源 常说的坏处 配置文件过大我就 ...
- Aop实现SqlSugar自动事务
http://www.cnblogs.com/jaycewu/p/7733114.html
- dp,px,pt,sp 的区别 以及dp 和 px 互转
dp = dip : device independent pixels(设备独立像素). 不同设备有不同的显示效果,这个和设备硬件有关,一般我们为了支持WVGA.HVGA和QVGA 推荐使用这个,不 ...
- java基本数据类型及其包装类
1.String类 String s1 = "hello world"; String s2 = "hello world"; String s3 = s1 + ...
- ASP.NET MVC中的路由IRouteConstraint方法应用实例
在如下代码的写法中: public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { ro ...
- SQL Server性能优化(8)堆表结构介绍
一.表结构综述 下图是SQL Server中表的组织形式(其中分区1.分区2是为了便于管理,把表进行分区,放到不同的硬盘数据文件里.默认情况下,表只有一个分区.).表在硬盘上的存放形式,有堆和B树两种 ...
- 对C#热更新方案ILRuntime的探究
转载请标明出处:http://www.cnblogs.com/zblade/ 对于游戏中的热更,目前主流的解决方案,分为Lua(ulua/slua/xlua/tolua)系和ILRuntime代表的c ...