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. 625. Minimum Factorization

    Problem statement Given a positive integer a, find the smallest positive integer b whose multiplicat ...

  2. 【2018.10.10】[HNOI2008] GT考试(bzoj1009)

    10pts: 暴力枚举字符串,Hash判是否出现.(真会有人写么) 时间复杂度$O(10^n*n)$. 40pts: 学过OI的人都会写的dp 如果这道题的40pts($n\le 250000$)设成 ...

  3. log4j详细配置解析

    出自:http://www.blogjava.net/zJun/archive/2006/06/28/55511.html Log4J的配置文件(Configuration File)就是用来设置记录 ...

  4. 区间翻转(codevs 3243)

    题目描述 Description 给出N个数,要求做M次区间翻转(如1 2 3 4变成4 3 2 1),求出最后的序列 输入描述 Input Description 第一行一个数N,下一行N个数表示原 ...

  5. Scrapy学习-10-Request&Response对象

    请求URL流程 Scarpy使用请求和响应对象来抓取网站  通常情况下,请求对象会在spider中生成,并在系统中传递,直到到达downloader,它执行请求并返回一个响应对象,该对象返回发送请求的 ...

  6. plsql + 客户端 连接oracle数据库

    一. 目录结构D:\oracle\instantclient_11_2D:\oracle\instantclient_11_2\tnsnames.ora 二. 环境变量 NLS_LANG = SIMP ...

  7. JavaScript 实现格式化字符串函数String.format (解决引号嵌套转义符问题)

    在js开发中,我们可能会遇到这样一个问题 当需要通过js动态插入html标签的时候 特别是当遇到大量的变量拼接.引号层层嵌套的情况,会出现转义字符问题,经常出错 我们来看个例子 <!DOCTYP ...

  8. SGU103+POJ 1158 最短路/dp

    题意:一个无向图,求起点到终点最少时间,限制:每个路口有灯,要灯颜色一样才能过去,灯之有俩种颜色,周期 变化,给定每个灯初态,时间. 思路:开始就想到直接DP,方程dp[k]=dp[i]+distan ...

  9. Oracle外键级联删除和级联更新

    https://www.2cto.com/database/201507/417496.html

  10. codeforces #472(div 1)

    B(two point) 题意: 给出长度为n的非递减数组E[1..n],对于所有三元组(i,j,k),1<=i<j<k<=n且Ek-Ei<=U,我们需要计算出最大的(E ...