LCT模板题;

话说xor和的意思是所有数xor一下;

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<algorithm>
using namespace std;
#define mid ((l+r)>>1)
#define LL long long
#define FILE "dealing"
#define up(i,j,n) for(LL i=(j);i<=(n);i++)
#define pii pair<int,int>
int read(){
int x=0,f=1,ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
return f*x;
}
const int maxn=306000,inf=100000000,mod=998244353;
int n,m,cnt;
int c[maxn][2],fa[maxn],rev[maxn],w[maxn],v[maxn],sum[maxn];
void reve(int x){rev[x]^=1,swap(c[x][0],c[x][1]);}
void updata(int x){sum[x]=sum[c[x][1]]^sum[c[x][0]]^v[x];}
void pushdown(int x){if(rev[x])rev[x]^=1,reve(c[x][1]),reve(c[x][0]);}
bool isroot(int x){return c[fa[x]][1]!=x&&c[fa[x]][0]!=x;}
void rotate(int x){
int y=fa[x],z=fa[y],d=c[y][1]==x;
if(!isroot(y))c[z][c[z][1]==y]=x;
fa[y]=x,fa[x]=z,fa[c[x][d^1]]=y;
c[y][d]=c[x][d^1],c[x][d^1]=y;
updata(y);updata(x);
}
int q[maxn],top=0;
void splay(int x){
q[++top]=x;
for(int i=x;!isroot(i);i=fa[i])q[++top]=fa[i];
while(top)pushdown(q[top--]);
while(!isroot(x)){
int y=fa[x],z=fa[y];
if(!isroot(y))
if(c[y][1]==x^c[z][1]==y)rotate(x);
else rotate(y);
rotate(x);
}
}
void access(int x){for(int t=0;x;t=x,x=fa[x])splay(x),c[x][1]=t,updata(x);}
void makeroot(int x){access(x);splay(x);reve(x);}
void link(int x,int y){makeroot(x);fa[x]=y;}
void cut(int x,int y){makeroot(x);access(y);splay(y);if(c[y][0]==x)fa[x]=c[y][0]=0;}
int main(){
freopen(FILE".in","r",stdin);
freopen(FILE".out","w",stdout);
n=read(),m=read();cnt=n;
up(i,1,n)sum[i]=v[i]=read();
int ch,x,y;
while(m--){
ch=read(),x=read(),y=read();
if(ch==0){
makeroot(x),access(y),splay(y);
printf("%d\n",sum[y]);
}
if(ch==1){
makeroot(x);access(y);splay(y);
int t=y;while(c[t][0])t=c[t][0];
if(t!=x)link(x,y);
}
if(ch==2)cut(x,y);
if(ch==3){makeroot(x);v[x]=y;updata(x);}
}
return 0;
}

  

【bzoj3282】Tree的更多相关文章

  1. 【BZOJ3282】Tree (Link-Cut Tree)

    [BZOJ3282]Tree (Link-Cut Tree) 题面 BZOJ权限题呀,良心luogu上有 题解 Link-Cut Tree班子提 最近因为NOIP考炸了 学科也炸了 时间显然没有 以后 ...

  2. 【BZOJ3282】Tree LCT

    1A爽,感觉又对指针重怀信心了呢= =,模板题,注意单点修改时splay就好,其实按吾本意是没写的也A了,不过应该加上能更好维护平衡性. ..还是得加上好= = #include <iostre ...

  3. 【POJ3237】Tree 树链剖分+线段树

    [POJ3237]Tree Description You are given a tree with N nodes. The tree's nodes are numbered 1 through ...

  4. 【BZOJ】【2631】Tree

    LCT 又一道名字叫做Tree的题目…… 看到删边加边什么的……又是动态树问题……果断再次搬出LCT. 这题比起上道[3282]tree的难点在于需要像线段树维护区间那样,进行树上路径的权值修改&am ...

  5. 【Luogu1501】Tree(Link-Cut Tree)

    [Luogu1501]Tree(Link-Cut Tree) 题面 洛谷 题解 \(LCT\)版子题 看到了顺手敲一下而已 注意一下,别乘爆了 #include<iostream> #in ...

  6. 【AtCoder3611】Tree MST(点分治,最小生成树)

    [AtCoder3611]Tree MST(点分治,最小生成树) 题面 AtCoder 洛谷 给定一棵\(n\)个节点的树,现有有一张完全图,两点\(x,y\)之间的边长为\(w[x]+w[y]+di ...

  7. 【HDU5909】Tree Cutting(FWT)

    [HDU5909]Tree Cutting(FWT) 题面 vjudge 题目大意: 给你一棵\(n\)个节点的树,每个节点都有一个小于\(m\)的权值 定义一棵子树的权值为所有节点的异或和,问权值为 ...

  8. 【BZOJ2654】Tree(凸优化,最小生成树)

    [BZOJ2654]Tree(凸优化,最小生成树) 题面 BZOJ 洛谷 题解 这道题目是之前\(Apio\)的时候写的,忽然发现自己忘记发博客了... 这个万一就是一个凸优化, 给所有白边二分一个额 ...

  9. 【POJ1741】Tree(点分治)

    [POJ1741]Tree(点分治) 题面 Vjudge 题目大意: 求树中距离小于\(K\)的点对的数量 题解 完全不觉得点分治了.. 简直\(GG\),更别说动态点分治了... 于是来复习一下. ...

随机推荐

  1. ngrinder的idea脚本开发环境配置

    1.安装toriseSvn,安装一定要选择comandline (默认是没选择的) 2.下载groovy,解压缩,在开发工具(ps:idea,eclipse)中设置groovy安装路径 3.在网站处创 ...

  2. java 数据库连接的几个步骤

    Class.forName("oracle.jdbc.driver.OracleDriver"); String url = "jdbc:oracle:thin:@你的主 ...

  3. SQL 随机取出一条数据

    今天遇到一需求,需要随机取出一条数据.网上找了下,sqlserver自带的有newID()这个函数,可以随机出来一个guid,用来取随机数还是蛮不错的. 直接上SQL: select top 1 *, ...

  4. 多语言业务错误日志收集监控工具Sentry 安装与使用

    Sentry 是一个实时事件日志记录和汇集的平台.其专注于错误监控以及提取一切事后处理所需信息而不依赖于麻烦的用户反馈. Sentry是一个日志平台, 它分为客户端和服务端,客户端(目前客户端有Pyt ...

  5. 4.JAVA语言基础部分—枚举与泛型

    枚举 //定义枚举 enum MyEnum{ ITEM_A, ITEM_B } public static void main(String[] args) { //values()获取所枚举项的集合 ...

  6. Maven使用site-deploy(site:deploy)部署通过site生成的文档(Tomcat-WebDAV)

    Maven可以通过site生成项目的帮助文档,并且格式为html,那么可以通过site-deploy把文档部署到远端,部署方式支持HTTP/FTP/SCM/WebDAV等. 更多部署方案,参考:htt ...

  7. php 解决MySQL插入数据出现 Incorrect string value: &#39;\xF0\x9F\x92\x8BTi...&#39;错误

    在项目中向MySQL插入数据时.发现数据插入不完整,通过调试,发现插入语句也没什么特殊的错误. 可是就是差不进去,于是就打开mysqli错误的调试 $ret = mysqli_query($this- ...

  8. linux 状态与系统调优

    什么样的cup 才算是负载高呢?才算忙呢?

  9. Android的activity的生命周期

    activity的生命周期有四个重要的状态:活动,暂停,停止,销毁 基本的方法有:onCreate.onStart.onResume.onPause.onStop.onDestory 最经常使用的方法 ...

  10. 【LeetCode从零单排】No 114 Flatten Binary Tree to Linked List

    题目 Given a binary tree, flatten it to a linked list in-place. For example,Given 1 / \ 2 5 / \ \ 3 4 ...