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> ...
随机推荐
- C#:异步编程和线程的使用(.NET 4.5 )
摘自:http://www.codeproject.com/Articles/996857/Asynchronous-programming-and-Threading-in-Csharp-N(葡萄城 ...
- 东大OJ-一元三次方程解的个数
1043: Fixed Point 时间限制: 5 Sec 内存限制: 128 MB 提交: 26 解决: 5 [提交][状态][讨论版] 题目描述 In mathematics, a fixed ...
- VMware精简系统Win系列|体积更小更稳定
此Win系列基于VMware10 给个我自用的超精简VM10.0.3 XP重新制作体积大了一点但更稳定,压缩包166M 制作了Win 2003,压缩包171.4M Win7重新制作体积更小更稳定,压缩 ...
- 【Spring】构建Springboot项目 实现restful风格接口
项目代码如下: package hello; import org.springframework.boot.SpringApplication; import org.springframework ...
- error_reporting()
定义和用法 error_reporting() 设置 PHP 的报错级别并返回当前级别. 语法 error_reporting(report_level) 如果参数 level 未指定,当前报错级别将 ...
- android开机自启动广播
权限<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> &l ...
- [转]oracle数据类型和对应的java类型
地址: http://otndnld.oracle.co.jp/document/products/oracle10g/102/doc_cd/java.102/B19275-03/datacc.htm ...
- mybatis中使用使用模块化sql
主要使用到mybatis中的标签 <sql id="tempId"> select * from student <sql> 使用的标签如下: <in ...
- c#学习<一> 基础知识
http://www.25hoursaday.com/CsharpVsJava.html ECMA-334 关键字 累计103 个,其中关键字77个,上下文关键字26个.(c#5.0) 标识符 1. ...
- java 读取数据库中表定义
将数据库中的表信息读取出来 package com.cloud.smartreport.utils; import java.sql.Connection; import java.sql.Datab ...