LCT..

--------------------------------------------------------------------------------

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
 
#define rep( i , n ) for( int i = 0 ; i < n ; ++i )
#define clr( x , c ) memset( x , c , sizeof( x ) )
 
using namespace std;
 
const int maxn = 300000 + 5;
const int maxnode = maxn + 100;
 
int n;
 
struct Node *pt , *null; 
 
struct Node {
Node *ch[ 2 ] , *p , *fa;
int v , x;
bool rev , isRoot;
Node( int _v = 0 ) : v( _v ) , x( _v ) {
ch[ 0 ] = ch[ 1 ] = p = fa = null;
rev = false;
isRoot = true;
}
inline bool d() {
return this == p -> ch[ 1 ];
}
inline void setc( Node* c , int d ) {
ch[ d ] = c;
c -> p = this;
}
inline void relax() {
if( rev ) {
rev = false;
rep( i , 2 ) if( ch[ i ] != null )
   ch[ i ] -> Rev();
}
}
inline void Rev() {
rev ^= 1;
swap( ch[ 0 ] , ch[ 1 ] );
}
inline void setRoot() {
fa = p;
p = null;
isRoot = true;
}
inline void upd() {
x = ch[ 0 ] -> x ^ v ^ ch[ 1 ] -> x;
}
void* operator new( size_t ) {
return pt++;
}
};
 
Node NODE[ maxnode ];
 
void rot( Node* t ) {
Node* p = t -> p;
p -> relax();
t -> relax();
int d = t -> d();
p -> p -> setc( t , p -> d() );
p -> setc( t -> ch[ d ^ 1 ] , d );
t -> setc( p , d ^ 1 );
p -> upd();
if( p -> isRoot ) {
p -> isRoot = false;
t -> isRoot = true;
t -> fa = p -> fa;
}
}
 
void splay( Node* t , Node* f = null ) {
static Node* S[ maxn ];
int top = 0;
for( Node* o = t ; o != null ; o = o -> p ) 
   S[ ++top ] = o;
while( top ) 
   S[ top-- ] -> relax();
for( Node* p = t -> p ; p != f ; p = t -> p ) {
if( p -> p != f )
   p -> d() != t -> d() ? rot( t ) : rot( p );
rot( t );
}
t -> upd();
}
void access( Node* t ) {
for( Node* o = null ; t != null ; o = t , t = t -> fa ) {
splay( t );
t -> ch[ 1 ] -> setRoot();
t -> setc( o , 1 );
}
}
 
void makeRoot( Node* t ) {
access( t );
splay( t );
t -> Rev();
}
 
Node* findRoot( Node* t ) {
access( t );
splay( t );
for( ; t -> ch[ 0 ] != null ; t = t -> ch[ 0 ] ) 
   t -> relax();
splay( t );
return t;
}
 
void join( Node* x , Node* y ) {
makeRoot( x );
x -> fa= y;
splay( y );
}
 
Node* get( Node* x , Node* y ) {
makeRoot( x );
access( y );
splay( y );
return y;
}
 
void cut( Node* x , Node* y ) {
makeRoot( x );
access( y );
splay( x );
x -> setc( null , 1 );
x -> upd();
y -> p = null;
y -> setRoot();
}
 
void init() {
pt = NODE;
null = new Node( 0 );
}
 
Node* V[ maxn ];
 
int main() {
freopen( "test.in" , "r" , stdin );
init();
int m;
cin >> n >> m;
rep( i , n ) {
int v;
scanf( "%d" , &v );
V[ i ] = new Node( v );
}
int x , y , op;
while( m-- ) {
scanf( "%d%d%d" , &op , &x , &y );
x-- , y--;
if( op == 3 ) {
y++;
access( V[ x ] );
splay( V[ x ] );
V[ x ] -> v = y;
V[ x ] -> upd();
} else if( ! op ) {
Node* t = get( V[ x ] , V[ y ] );
printf( "%d\n" , get( V[ x ] , V[ y ] ) -> x );
} else if( op == 1 ) {
if( findRoot( V[ x ] ) != findRoot( V[ y ] ) )
   join( V[ x ] , V[ y ] );
} else {
if( findRoot( V[ x ] ) == findRoot( V[ y ] ) )
   cut( V[ x ] , V[ y ] );
}
}
return 0;
}

--------------------------------------------------------------------------------

3282: Tree

Time Limit: 30 Sec  Memory Limit: 512 MB
Submit: 827  Solved: 341
[Submit][Status][Discuss]

Description

给定N个点以及每个点的权值,要你处理接下来的M个操作。操作有4种。操作从0到3编号。点从1到N编号。

0:后接两个整数(x,y),代表询问从x到y的路径上的点的权值的xor和。保证x到y是联通的。

1:后接两个整数(x,y),代表连接x到y,若x到Y已经联通则无需连接。

2:后接两个整数(x,y),代表删除边(x,y),不保证边(x,y)存在。

3:后接两个整数(x,y),代表将点X上的权值变成Y。

Input

第1行两个整数,分别为N和M,代表点数和操作数。

第2行到第N+1行,每行一个整数,整数在[1,10^9]内,代表每个点的权值。

第N+2行到第N+M+1行,每行三个整数,分别代表操作类型和操作所需的量。

Output

对于每一个0号操作,你须输出X到Y的路径上点权的Xor和。

Sample Input

3 3
1
2
3
1 1 2
0 1 2
0 1 1

Sample Output

3
1

HINT

1<=N,M<=300000

Source

BZOJ 3282: Tree( LCT )的更多相关文章

  1. [BZOJ 3282] Tree 【LCT】

    题目链接:BZOJ - 3282 题目分析 这道题是裸的LCT,包含 Link , Cut 和询问两点之间的路径信息. 写代码时出现的错误:Access(x) 的循环中应该切断的是原来的 Son[x] ...

  2. BZOJ 3282: Tree

    3282: Tree Time Limit: 30 Sec  Memory Limit: 512 MBSubmit: 1714  Solved: 765[Submit][Status][Discuss ...

  3. bzoj 3282: Tree (Link Cut Tree)

    链接:https://www.lydsy.com/JudgeOnline/problem.php?id=3282 题面: 3282: Tree Time Limit: 30 Sec  Memory L ...

  4. BZOJ 3282 Tree Link-Cut-Tree(LCT)

    题目大意: 给定N个点以及每一个点的权值,要你处理接下来的M个操作.操作有4种.操作从0到3编号.点从1到N编号. 0:后接两个整数(x,y),代表询问从x到y的路径上的点的权值的xor和.保证x到y ...

  5. BZOJ 2631: tree( LCT )

    LCT...略麻烦... -------------------------------------------------------------------------------- #inclu ...

  6. BZOJ 3282 Tree(动态树)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3282 [题目大意] 0:后接两个整数(x,y),代表询问从x到y的路径上的点的权值的x ...

  7. BZOJ 3282 Tree ——KD-Tree

    [题目分析] 明显的LCT维护连通性的题目. access的操作是比较巧妙的,可以把结点到根变成偏爱路径,而且保证了该点是链上深度最深的点. 而且需边的思想也很巧妙,保证了复杂度. 但是只能用于修改路 ...

  8. BZOJ 2631: tree [LCT splay区间]

    2631: tree Time Limit: 30 Sec  Memory Limit: 128 MBSubmit: 3854  Solved: 1292[Submit][Status][Discus ...

  9. BZOJ 3282 Tree ——Link-Cut Tree

    [题目分析] 明显的LCT维护连通性的题目. access的操作是比较巧妙的,可以把结点到根变成偏爱路径,而且保证了该点是链上深度最深的点. 而且需边的思想也很巧妙,保证了复杂度. 但是只能用于修改路 ...

随机推荐

  1. centos6.5安装vsftpd

    开通FTP有gssftp和vsftpd二种,查了查,据说vsftpd更稳定和更安全.就用vsftpd吧. 什么是vsftpd vsftpd是一款在Linux发行版中最受推崇的FTP服务器程序.特点是小 ...

  2. [置顶] WebService调用工具(AXIS2)

    package com.metarnet.util; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Meth ...

  3. [LeetCode]题解(python):128-Longest Consecutive Sequence

    题目来源: https://leetcode.com/problems/longest-consecutive-sequence/ 题意分析: 给定一个没有排好序的数组,找到最长的连续序列的长度.要求 ...

  4. [LeetCode]题解(python):003-Longest Substring Without Repeating Characters

    题目来源: https://leetcode.com/problems/longest-substring-without-repeating-characters/ 题意分析: 题目是要求出最长的不 ...

  5. GC算法之串行并行并发

    串行收集器: 用单线程处理所有垃圾回收工作,因为无需多线程交互,所以效率比较高.但是,也无法使用多处理器的优势,所以此收集器适合单处理器机器.当然,此收集器也可以用在小数据量(100M左右)情况下的多 ...

  6. Aptana jQuery自动提示

    参考 http://www.ghugo.com/aptana-studio-3-jquery-autocomplete/ 对于第一种方案 是每个项目都能生效的  不过有时候网络不好时就无法顺利获取提示 ...

  7. MVC-Easy-UI-datagrid-分页-查询

    时间仓促,代码写的乱,莫怪,着影区不用理会(功能之外) <link href="@Url.Content("~/Content/Site.css")" r ...

  8. linux如何关闭selinux?

    首先我们可以用命令来查看selinux的状态getenforce 这个命令可以查看到selinux的状态,当前可以看到是关闭状态的.还有一个命令也可以查看出selinux的状态.sestatus -v ...

  9. RII K25A 语音空中飞鼠 红外学习步骤

    1.按住多功能遥控器上的SET按键,超过4秒不要放手,LED指示灯会闪一次,然后长亮.2.将多功能遥控器的红外口对准你原来的遥控器的红外口,然后按RII多功能遥控器面上任何按钮,上面灯将会闪动,闪动过 ...

  10. 我被SQL注入撞了一下腰

    网站的注入漏洞,应该说绝大多数做web开发的人都知道的事情.可是没想到从事6,7年开发工作的我,却会在这上栽了跟头,真是郁闷啊.心情很纠结,按照老婆的话,怎么感觉我像失恋了一样. 事情的起因还是在几个 ...