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. php那些坑

    1.创建数组不是new array(),是$aaa=array(),没有new,数组可以传入键值$aaa=array("key"=>"value"); 2 ...

  2. (转)java 中变量存储位置总结

    1.寄存器:最快的存储区, 由编译器根据需求进行分配,我们在程序中无法控制. 2. 栈:存放基本类型的变量数据和对象的引用,但对象本身不存放在栈中,而是存放在堆(new 出来的对象)或者常量池中(字符 ...

  3. 438. Find All Anagrams in a Strin

    Given a string s and a non-empty string p, find all the start indices of p's anagrams in s. Strings ...

  4. 最小费用最大流粗解 poj2516

    最小费用最大流,一般解法如下: 在流量基础上,每条边还有权费用,即单位流量下的所需费用.在最大流量下,求最小费用.解法:在最大流算法基础上,每次按可行流增广改为每次用spfa按最小费用(用单位费用)增 ...

  5. HTML 中 SELECT 选项分组

    <select name="viewType"> <option value selected>选择排序/显示方式</option> <o ...

  6. 2017 ACM/ICPC Asia Regional Urumuqi Online 记录

    比赛题目链接  Urumuqi

  7. <!--#include 引入失败

    在html中使用了<!--#include file="a.html">,结果发现页面上并没有引入到a.html页面,F12看是以注释的形式展示出来了,百度了很久. 最 ...

  8. 在springboot项目中获取pom.xml中的信息

    最近做了一个新项目,用到了springboot.在搭建框架的过程中,需要读取pom.xml中version的值,本来想着是用自己用java解析xml来着.没想到maven提供了这么一个包,可以直接获取 ...

  9. J粒子发现40周年-丁肇中中科院讲座笔记

    J粒子发现40周年-丁肇中中科院讲座笔记 华清远见2014-10-18   北京海淀区  张俊浩 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveXVuZm ...

  10. Delphi 的内存操作函数(1): 给字符指针分配内存

    马上能想到的函数有: GetMem AllocMem ReallocMem FreeMem GetMemory ReallocMemory FreeMemory New Dispose NewStr ...