思路:

用主席树维护并查集森林,每次连接时新增结点。
似乎并不需要启发式合并,我随随便便写了一个就跑到了3674第一页?
3673是这题的弱化版,本来写个暴力就能过,现在借用加强版的代码(去掉异或),直接吊打暴力程序。

 #include<cstdio>
#include<cctype>
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'';
while(isdigit(ch=getchar())) x=(((x<<)+x)<<)+(ch^'');
return x;
}
const int N=,SIZE=;
class PresistentDisjointSet {
private:
unsigned int left[SIZE],right[SIZE],sz;
int anc[SIZE];
unsigned int newnode() {
return sz++;
}
unsigned int getpos(const unsigned int p,const int b,const int e,const int x) {
if(b==e) return p;
int mid=(b+e)>>;
return (x<=mid)?getpos(left[p],b,mid,x):getpos(right[p],mid+,e,x);
}
public:
unsigned int root[N];
PresistentDisjointSet() {
sz=;
}
void Build(unsigned int &p,const int b,const int e) {
p=newnode();
if(b==e) {
anc[p]=b;
return;
}
int mid=(b+e)>>;
Build(left[p],b,mid);
Build(right[p],mid+,e);
}
unsigned int find(const unsigned int p,const int b,const int e,const int x) {
int q=getpos(p,b,e,x);
return x==anc[q]?q:find(p,b,e,anc[q]);
}
unsigned int Union2(const unsigned int p,const int b,const int e,const int x,const int y) {
unsigned int new_p=newnode();
if(b==e) {
anc[new_p]=y;
return new_p;
}
int mid=(b+e)>>;
if(x<=mid) left[new_p]=Union2(left[p],b,mid,x,y),right[new_p]=right[p];
if(x>mid) right[new_p]=Union2(right[p],mid+,e,x,y),left[new_p]=left[p];
return new_p;
}
bool isConnected(const int x,const int y) {
return anc[x]==anc[y];
}
unsigned int Union(const unsigned int p,const int b,const int e,int x,int y) {
x=find(p,b,e,x),y=find(p,b,e,y);
if(isConnected(x,y)) return p;
return Union2(p,b,e,anc[x],anc[y]);
}
};
PresistentDisjointSet s;
int main() {
int n=getint(),lastans=;
s.Build(s.root[],,n);
int m=getint();
for(register int i=;i<=m;i++) {
int op=getint();
if(op==) s.root[i]=s.Union(s.root[i-],,n,getint()^lastans,getint()^lastans);
else if(op==) s.root[i]=s.root[getint()^lastans];
else s.root[i]=s.root[i-],printf("%d\n",lastans=s.isConnected(s.find(s.root[i],,n,getint()^lastans),s.find(s.root[i],,n,getint()^lastans)));
}
return ;
}

[BZOJ3674]可持久化并查集加强版&[BZOJ3673]可持久化并查集 by zky的更多相关文章

  1. 【BZOJ】3673: 可持久化并查集 by zky & 3674: 可持久化并查集加强版(可持久化线段树)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3674 http://www.lydsy.com/JudgeOnline/problem.php?id ...

  2. bzoj 3673&3674 可持久化并查集&加强版(可持久化线段树+启发式合并)

    CCZ在2015年8月25日也就是初三暑假要结束的时候就已经能切这种题了%%% 学习了另一种启发式合并的方法,按秩合并,也就是按树的深度合并,实际上是和按树的大小一个道理,但是感觉(至少在这题上)更好 ...

  3. 2019.01.21 bzoj3674: 可持久化并查集加强版(主席树+并查集)

    传送门 题意:维护可持久化并查集,支持在某个版本连边,回到某个版本,在某个版本 询问连通性. 思路: 我们用主席树维护并查集fafafa数组,由于要查询历史版本,因此不能够用路径压缩. 可以考虑另外一 ...

  4. bzoj3673可持久化并查集 by zky&&bzoj3674可持久化并查集加强版

    bzoj3673可持久化并查集 by zky 题意: 维护可以恢复到第k次操作后的并查集. 题解: 用可持久化线段树维护并查集的fa数组和秩(在并查集里的深度),不能路径压缩所以用按秩启发式合并,可以 ...

  5. 【BZOJ3673/3674】可持久化并查集/可持久化并查集加强版 可持久化线段树

    [BZOJ3674]可持久化并查集加强版 Description Description:自从zkysb出了可持久化并查集后……hzwer:乱写能AC,暴力踩标程KuribohG:我不路径压缩就过了! ...

  6. [BZOJ3673&3674]可持久化并查集&加强版

    题目大意:让你实现一个可持久化的并查集(3674强制在线). 解题思路:刚刚介绍了一个叫rope的神器:我是刘邦,在这两题(实际上两题没什么区别)就派上用场了. 正解应该是主席树||可持久化平衡树,然 ...

  7. BZOJ 3674 可持久化并查集加强版(路径压缩版本)

    /* bzoj 3674: 可持久化并查集加强版 http://www.lydsy.com/JudgeOnline/problem.php?id=3674 用可持久化线段树维护可持久化数组从而实现可持 ...

  8. BZOJ 3674 可持久化并查集加强版(按秩合并版本)

    /* bzoj 3674: 可持久化并查集加强版 http://www.lydsy.com/JudgeOnline/problem.php?id=3674 用可持久化线段树维护可持久化数组从而实现可持 ...

  9. BZOJ3673 可持久化并查集 by zky 【主席树】

    BZOJ3673 可持久化并查集 by zky Description n个集合 m个操作 操作: 1 a b 合并a,b所在集合 2 k 回到第k次操作之后的状态(查询算作操作) 3 a b 询问a ...

随机推荐

  1. Mysql Binlog三种格式介绍及分析【转】

    一.Mysql Binlog格式介绍       Mysql binlog日志有三种格式,分别为Statement,MiXED,以及ROW! 1.Statement:每一条会修改数据的sql都会记录在 ...

  2. WebSphere的jython编码的一个坑

    was5.1版本,用"name=" in line这类判断字符串包含的方式时,系统会提示报错 TypeError: string member test needs char le ...

  3. 005_awk案例实战

    一.工作经验总结. (1)日志案例: 10.100.194.39 10.100.194.39 1019-03-16T11:01:04+08:00 www.uuwatch.com^^3FF91DE01B ...

  4. (常用)time,datetime,random,shutil(zipfile,tarfile),sys模块

    a.time模块import time 时间分为三种形式1.时间戳 (时间秒数的表达形式, 从1970年开始)print(time.time())start_time=time.time()time. ...

  5. centos6.5下编译安装mariadb-10.0.20

    源码编译安装mariadb-10.0.20.tar.gz 一.安装cmake编译工具 跨平台编译器 # yum install -y gcc* # yum install -y cmake 解决依赖关 ...

  6. mysql更新字段值提示You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode

    1 引言 当更新字段缺少where语句时,mysql会提示一下错误代码: Error Code: 1175. You are using safe update mode and you tried ...

  7. 如何从现有版本升级到element UI2.0?使用npm-check-updates

    转:https://blog.csdn.net/wojiaomaxiaoqi/article/details/78428738 登录element UI官网时提示2.0已经正式发布了,Element ...

  8. oracle进阶之connect by笔记

    本博客是自己在学习和工作途中的积累与总结,仅供自己参考,也欢迎大家转载,转载时请注明出处. http://www.cnblogs.com/king-xg/p/6794562.html 如果觉得对您有帮 ...

  9. java selenium操作safari

    SafariDriver是一个Safari浏览器的扩展.和Firefox类似,在selenium-safari-driver-xxx.jar包中org.openqa.selenium.safari路径 ...

  10. vue构建项目全过程

    1.node版本请更新到6.9.X版本以上,不然npm依赖会出问题 2.命令行里运行npm install --global vue-cli 3.npm install --global webpac ...