BZOJ3282: Tree
又是权限题= =,过了NOIp我就要去当一只权限狗!
LCT裸题,get到了两个小姿势。
1.LCA操作应该在access中随时updata
2.Link操作可以更简单
void Link(int noda,int nodb){Reverse(noda);t[noda].fa=nodb;}
//BZOJ 3282
//by Cydiater
//2016.9.16
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <ctime>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <string>
using namespace std;
#define ll long long
#define up(i,j,n) for(int i=j;i<=n;i++)
#define down(i,j,n) for(int i=j;i>=n;i--)
;
const int oo=0x3f3f3f3f;
inline int read(){
,f=;
;ch=getchar();}
+ch-';ch=getchar();}
return x*f;
}
;
struct Tree{
],v,Xor,fa,tag;
}t[MAXN];
namespace solution{
inline ]==node;}
inline ]!=node&&t[t[node].fa].son[]!=node;}
inline void updata(int node){
if(node){
t[node].Xor=t[node].v;
])t[node].Xor^=t[t[node].son[]].Xor;
])t[node].Xor^=t[t[node].son[]].Xor;
}
}
inline void downit(int node){
if(t[node].tag){
t[t[node].son[]].tag^=;t[t[node].son[]].tag^=;
swap(t[node].son[],t[node].son[]);
t[node].tag=;
}
}
void rotate(int node){
int old=t[node].fa,oldf=t[old].fa,which=get(node);
]==old]=node;
t[old].son[which]=t[node].son[which^];t[t[old].son[which]].fa=old;
t[node].son[which^]=old;t[old].fa=node;t[node].fa=oldf;
updata(old);updata(node);
}
void splay(int node){
top=;q[++top]=node;
for(int i=node;!isroot(i);i=t[i].fa)q[++top]=t[i].fa;
down(i,top,)downit(q[i]);
while(!isroot(node)){
int old=t[node].fa,oldf=t[old].fa;
if(!isroot(old))rotate(get(node)==get(old)?old:node);
rotate(node);
}
}
void access(int node){
;
while(node){
splay(node);
t[node].son[]=tmp;
updata(node);tmp=node;
node=t[node].fa;
}
}
;}
void Link(int noda,int nodb){Reverse(noda);t[noda].fa=nodb;}
]==nodea)t[nodb].son[]=t[noda].fa=;}
void LCA(int noda,int nodb){Reverse(nodb);access(noda);splay(noda);}
int find(int node){
access(node);splay(node);
int tmp=node;
])tmp=t[tmp].son[];
return tmp;
}
void change(int node,int num){
access(node);splay(node);//down lazy_tag
t[node].v=num;updata(node);
}
//Link-Cut-Tree
void init(){
N=read();M=read();
up(i,,N){
t[i].v=read();
t[i].son[]=t[i].son[]=;
t[i].Xor=t[i].v;t[i].fa=;
}
}
void slove(){
while(M--){
op=read();
){
nodea=read();nodeb=read();
LCA(nodea,nodeb);printf("%d\n",t[nodea].Xor);
}
){
nodea=read();nodeb=read();
if(find(nodea)==find(nodeb))continue;
Link(nodea,nodeb);
}
){
nodea=read();nodeb=read();
if(find(nodea)!=find(nodeb))continue;
Cut(nodea,nodeb);
}
){
node=read();num=read();
change(node,num);
}
}
}
}
int main(){
//freopen("input.in","r",stdin);
using namespace solution;
init();
slove();
;
}
BZOJ3282: Tree的更多相关文章
- BZOJ3282——Tree
1.题目大意:动态树问题,点修改,链查询xor和 裸题一道.. #include <stack> #include <cstdio> #include <cstdlib& ...
- BZOJ-3282 Tree Link-Cut-Tree(似乎树链剖分亦可)
蛋蛋用链剖A的,我写的LCT 3282: Tree Time Limit: 30 Sec Memory Limit: 512 MB Submit: 1241 Solved: 542 [Submit][ ...
- [bzoj3282]Tree (lct)
昨天看了一天的lct..当然幸好最后看懂了(也许吧..) 论善良学长的重要性T_T,老司机带带我! 这题主要是删边的时候还要判断一下..蒟蒻一开始天真的以为存在的边才能删结果吃了一发wa... 事实是 ...
- BZOJ3282: Tree (LCT模板)
Description 给定N个点以及每个点的权值,要你处理接下来的M个操作. 操作有4种.操作从0到3编号.点从1到N编号. 0:后接两个整数(x,y),代表询问从x到y的路径上的点的权值的xor和 ...
- 【学习心得】Link-cut Tree
Link-cut Tree是一种支持改变树(森林)的形态(link和cut),同时维护树的路径上节点信息的数据结构.lct通过splay来维护每次的perferred path,说白了就是一个动态的树 ...
- AHOI2018训练日程(3.10~4.12)
(总计:共90题) 3.10~3.16:17题 3.17~3.23:6题 3.24~3.30:17题 3.31~4.6:21题 4.7~4.12:29题 ZJOI&&FJOI(6题) ...
- 【BZOJ3282】Tree (Link-Cut Tree)
[BZOJ3282]Tree (Link-Cut Tree) 题面 BZOJ权限题呀,良心luogu上有 题解 Link-Cut Tree班子提 最近因为NOIP考炸了 学科也炸了 时间显然没有 以后 ...
- 【BZOJ3282】Tree LCT
1A爽,感觉又对指针重怀信心了呢= =,模板题,注意单点修改时splay就好,其实按吾本意是没写的也A了,不过应该加上能更好维护平衡性. ..还是得加上好= = #include <iostre ...
- 【bzoj3282】Tree
LCT模板题: 话说xor和的意思是所有数xor一下: #include<iostream> #include<cstdio> #include<cstring> ...
随机推荐
- UWP开源项目 LLQNotifier 页面间通信利器(移植EventBus)
前言 EventBus是一个Android版本的页面间通信库,这个库让页面间的通信变得十分容易且大幅降低了页面之间的耦合.小弟之前玩Android的时候就用得十分顺手,现在玩uwp就觉得应该在这平台也 ...
- hibernate Expression详解
关键字: hibernate expression hibernate Expression详解Expression.gt:对应SQL条件中的"field > value " ...
- PS技能大全
1.设置固定的图片大小 参考:http://jingyan.baidu.com/album/642c9d3418bec4644a46f72a.html?picindex=1
- 【JavaScript】 knockout.js 日期格式化借助【momentjs】
源:Knockout.js 日期格式化 源:momentjs
- Hadoop配置安装手册
本次Hadoop集群安装一共使用四个节点,各节点IP如下: Master 172.22.120.191 Slave1 172.22.120.192 Slave2 172.22.120.193 Slav ...
- IntelliJ idea的使用
1.快捷键 2.插件集成 附录:参考资料
- <诗经>的由来
<人间词话七讲> 第一讲 那是一个把各地的歌谣都编辑在一起的collection. 而且, 它被编辑的时候有一个目的, 在周朝的时候有采诗之官, 他们采集各地的歌谣, 以观民风, 用来给周 ...
- Eclipse SVN插件与TortoiseSVN的对应关系及下载链接
Eclipse SVN 插件与TortoiseSVN对应关系 Eclipse 3.2/Callisto, 3.3/Europa, 3.4/Ganymede, 3.5/Galileo, 3.6/Heli ...
- DTD中的属性类型
<![CDATA[文本内容]]> DTD中的属性类型 全名:character data 在标记CDATA下,所有的标记.实体引用都被忽略,而被XML处理程序一视同仁地当做字符数据看待, ...
- shell截取字符串的方法
参考文献: linux中shell截取字符串方法总结 [Linux]如何在Shell脚本中计算字符串长度? 截取字符串的方法一共有八种,主要为以下方法 shell中截取字符串的方法有很多中, ${ex ...