回顾一下LCT,容易写错的地方:

  1、每次断掉Splay中的边,必须update一下父亲节点,再根据具体情况是否splay父亲节点。

  2、养成没有用的值(比如当pre[u]不为0时的pnt[u])不去乱修改的习惯。

 /**************************************************************
Problem: 3282
User: idy002
Language: C++
Result: Accepted
Time:2968 ms
Memory:10712 kb
****************************************************************/ #include <cstdio>
#include <utility>
#include <set>
#define N 300010
using namespace std; typedef pair<int,int> dpr; struct Lct {
int pnt[N], pre[N], son[N][], val[N], xsum[N], rtg[N]; void update( int nd ) {
xsum[nd] = val[nd];
if( son[nd][] ) xsum[nd] ^= xsum[son[nd][]];
if( son[nd][] ) xsum[nd] ^= xsum[son[nd][]];
}
void rotate( int nd, int d ) {
int p=pre[nd];
int s=son[nd][!d];
int ss=son[s][d]; son[nd][!d] = ss;
son[s][d] = nd;
if( p ) son[p][ nd==son[p][] ] = s;
else {
pnt[s]=pnt[nd];
pnt[nd] = ;
} pre[nd] = s;
pre[s] = p;
if( ss ) pre[ss] = nd; update( nd );
update( s );
}
void pushdown( int nd ) {
if( rtg[nd] ) {
int &ls=son[nd][], &rs=son[nd][];
swap(ls,rs);
if( ls ) rtg[ls] ^= ;
if( rs ) rtg[rs] ^= ;
rtg[nd] = ;
}
}
void big_push( int nd ) {
if( pre[nd] ) big_push(pre[nd]);
pushdown(nd);
}
void splay( int nd, int top= ) {
big_push( nd );
while( pre[nd]!=top ) {
int p=pre[nd];
int nl=nd==son[p][];
if( pre[p]==top ) {
rotate( p, nl );
} else {
int pp=pre[p];
int pl=p==son[pp][];
if( nl==pl ) {
rotate( pp, pl );
rotate( p, nl );
} else {
rotate( p, nl );
rotate( pp, pl );
}
}
}
}
void access( int nd ) {
int u=nd;
int v=;
while( u ) {
splay(u);
int s=son[u][];
if( s ) {
pre[s] = ;
pnt[s] = u;
}
if( v ) {
pre[v] = u;
pnt[v] = ;
}
son[u][] = v;
update(u);
v = u;
u = pnt[u];
}
splay(nd);
}
int findroot( int u ) {
while( pre[u] ) u=pre[u];
while( pnt[u] ) {
u=pnt[u];
while( pre[u] ) u=pre[u];
}
return u;
}
void makeroot( int u ) {
access(u);
rtg[u] ^= ;
}
void cut( int u, int v ) {
makeroot(u);
access(v);
pnt[u] = pre[u] = ;
son[v][] = ;
update(v);
}
void link( int u, int v ) {
makeroot(u);
makeroot(v);
pnt[u] = v;
}
int query( int u, int v ) {
makeroot(u);
access(v);
return xsum[v];
}
void modify( int u, int v ) {
access(u);
xsum[u] ^= val[u];
val[u] = v;
xsum[u] ^= val[u];
}
}T; int n, m;
set<dpr> st; int main() {
scanf( "%d%d", &n, &m );
for( int i=,w; i<=n; i++ ) {
scanf( "%d", &w );
T.modify( i, w );
}
for( int i=,opt,u,v; i<=m; i++ ) {
scanf( "%d%d%d", &opt, &u, &v );
if( opt== ) {
printf( "%d\n", T.query(u,v) );
} else if( opt== ) {
if( u>v ) swap(u,v);
if( T.findroot(u)!=T.findroot(v) ) {
st.insert( dpr(u,v) );
T.link(u,v);
}
} else if( opt== ) {
if( u>v ) swap(u,v);
if( st.count( dpr(u,v) ) ) {
st.erase( dpr(u,v) );
T.cut(u,v);
}
} else {
T.modify( u, v );
}
}
}

bzoj 3282的更多相关文章

  1. BZOJ 2002 && BZOJ 2409 LCT && BZOJ 3282 初步练习

    #include <cstdio> ; inline void Get_Int(int & x) { ; ') ch=getchar(); +ch-'; ch=getchar(); ...

  2. [BZOJ 3282] Tree 【LCT】

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

  3. BZOJ 3282: Tree( LCT )

    LCT.. -------------------------------------------------------------------------------- #include<c ...

  4. bzoj 3282: Tree (Link Cut Tree)

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

  5. BZOJ 3282: Tree

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

  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 3282】Tree Link Cut Tree模板题

    知道了为什么要换根(changeroot),access后为什么有时要splay,以及LCT的其他操作,算是比较全面的啦吧,,, 现在才知道这些,,,真心弱,,, #include<cstdio ...

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

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

随机推荐

  1. C# FileStream进行FTP服务上传文件和下载文件

    定义FileStream类的操作类:操作类名: FtpUpDown 上传文件 /// <summary> /// 上传文件 /// </summary> /// <par ...

  2. 七、springcloud之配置中心Config(二)之高可用集群

    方案一:传统作法(不推荐) 服务端负载均衡 将所有的Config Server都指向同一个Git仓库,这样所有的配置内容就通过统一的共享文件系统来维护,而客户端在指定Config Server位置时, ...

  3. Python爬虫学习1: Requests模块的使用

    Requests函数库是学习Python爬虫必备之一, 能够帮助我们方便地爬取. Requests: 让HTTP服务人类. 本文主要参考了其官方文档. Requests具有完备的中英文文档, 能完全满 ...

  4. 字体格式类型(.eot/.otf/.woff/.svg)

    @font-face语句是css中的一个功能模块,用于实现网页字体多样性的模块(设计者可随意指定字体,不需要考虑浏览者电脑上是否安装). @font-face文件 而由于网页中使用的字体类型,也是各浏 ...

  5. RobotCraft 2017 第二届国际机器人学暑期学校 2nd Edition of International Robotics Summer School

    原文网址:http://www.ros.org/news/2017/02/2nd-edition-of-international-robotics-summer-school-robotcraft- ...

  6. mysql 导出数据库命令

    mysqldump --socket=/data/mysql/mysql.sock -uroot -pfanzhuo -d stat1> stat1.sql

  7. (最大矩阵链乘)Matrix-chain product

    Matrix-chain product. The following are some instances. a)       <3, 5, 2, 1,10> b)       < ...

  8. Java第三阶段学习(一、IO流------File类)

    一.IO概述: 把内存中的数据存入到硬盘(持久化设备)中叫做:输出(写)Output操作.JAVA软件往电脑硬盘上走叫输出. 把硬盘中的数据读取到到内存里叫做:输入(读)Input操作.电脑硬盘上往J ...

  9. echart 打开新世界的大门

    实时折线图 option = { backgroundColor:'#2B2B2B', tooltip: { trigger: 'axis' }, legend: { data:['频率'], tex ...

  10. USACO 5.4 Character Recognition

    Character Recognition This problem requires you to write a program that performs character recogniti ...