最后还是去掉异或顺手A了3673,,,

并查集其实就是fa数组,我们只需要维护这个fa数组,用可持久化线段树就行啦

1:判断是否属于同一集合,我加了路径压缩。

2:直接把跟的值指向root[k]的值破之。

3:输出判断即可。

难者不会,会者不难,1h前我还在膜这道题,现在吗hhh就当支持下zky学长出的题了。

3673:

#include<cstdio>
#include<cstring>
#include<algorithm>
#define read(x) x=getint()
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
using namespace std;
inline const int getint(){char c=getchar();int k=1,r=0;for(;c<'0'||c>'9';c=getchar())if(c=='-')k=-1;for(;c>='0'&&c<='9';c=getchar())r=r*10+c-'0';return k*r;}
const int N=2*1E4+10;
struct node{int l,r,f;}T[N*100];
int cnt,root[N],n,m;
inline void update(int l,int r,int &pos,int x,int fa){
T[++cnt]=T[pos]; pos=cnt;
if (l==r) {T[pos].f=fa; return;}
int mid=(l+r)>>1;
if (x<=mid) update(l,mid,T[pos].l,x,fa);
else update(mid+1,r,T[pos].r,x,fa);
}
inline int ask(int l,int r,int pos,int x){
if (l==r) return T[pos].f;
int mid=(l+r)>>1;
if (x<=mid) return ask(l,mid,T[pos].l,x);
else return ask(mid+1,r,T[pos].r,x);
}
inline int un(int &rt,int a,int b){
update(1,n,rt,a,b);
return b;
}
inline int find(int &rt,int y){
int f=ask(1,n,rt,y);
return f==y?y:un(rt,y,find(rt,f));
}
int main(){
read(n); read(m); int fx,fy,x,y,c;
for1(i,1,n) update(1,n,root[0],i,i);
for1(i,1,m){
read(c);
root[i]=root[i-1];
switch (c){
case 1:
read(x); read(y);
fx=find(root[i],x),fy=find(root[i],y);
if (fx!=fy) un(root[i],fx,fy);
break;
case 2:
root[i]=root[getint()];
break;
case 3:
read(x); read(y);
fx=find(root[i],x),fy=find(root[i],y);
printf("%d\n",(fx==fy));
break;
}
}return 0;
}

3674:

#include<cstdio>
#include<cstring>
#include<algorithm>
#define read(x) x=getint()
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
using namespace std;
inline const int getint(){char c=getchar();int k=1,r=0;for(;c<'0'||c>'9';c=getchar())if(c=='-')k=-1;for(;c>='0'&&c<='9';c=getchar())r=r*10+c-'0';return k*r;}
const int N=2*1E5+10;
struct node{int l,r,f;}T[N*100];
int cnt,root[N],n,m;
inline void update(int l,int r,int &pos,int x,int fa){
T[++cnt]=T[pos]; pos=cnt;
if (l==r) {T[pos].f=fa; return;}
int mid=(l+r)>>1;
if (x<=mid) update(l,mid,T[pos].l,x,fa);
else update(mid+1,r,T[pos].r,x,fa);
}
inline int ask(int l,int r,int pos,int x){
if (l==r) return T[pos].f;
int mid=(l+r)>>1;
if (x<=mid) return ask(l,mid,T[pos].l,x);
else return ask(mid+1,r,T[pos].r,x);
}
inline int un(int &rt,int a,int b){
update(1,n,rt,a,b);
return b;
}
inline int find(int &rt,int y){
int f=ask(1,n,rt,y);
return f==y?y:un(rt,y,find(rt,f));
}
int main(){
read(n); read(m); int fx,fy,last=0,x,y,c;
for1(i,1,n) update(1,n,root[0],i,i);
for1(i,1,m){
read(c);
root[i]=root[i-1];
switch (c){
case 1:
read(x); read(y); x^=last; y^=last;
fx=find(root[i],x),fy=find(root[i],y);
if (fx!=fy) un(root[i],fx,fy);
break;
case 2:
root[i]=root[getint()^last];
break;
case 3:
read(x); read(y); x^=last; y^=last;
fx=find(root[i],x),fy=find(root[i],y);
printf("%d\n",last=(fx==fy));
break;
}
}return 0;
}

这样就完了,然而只是达神几年前就随手虐的东西,本蒟蒻必须得努力啊!!!

【BZOJ 3674】可持久化并查集加强版&【BZOJ 3673】可持久化并查集 by zky 用可持久化线段树破之的更多相关文章

  1. 【BZOJ4388】JOI2012 invitation 堆+线段树+并查集(模拟Prim)

    [BZOJ4388]JOI2012 invitation Description 澳洲猴举办了一场宴会,他想要邀请A个男生和B个女生参加,这A个男生从1到A编号,女生也从1到B编号.现在澳洲猴知道n组 ...

  2. 【bzoj4399】魔法少女LJJ 并查集+权值线段树合并

    题目描述 在森林中见过会动的树,在沙漠中见过会动的仙人掌过后,魔法少女LJJ已经觉得自己见过世界上的所有稀奇古怪的事情了LJJ感叹道“这里真是个迷人的绿色世界,空气清新.淡雅,到处散发着醉人的奶浆味: ...

  3. bzoj 2733: [HNOI2012]永无乡 -- 线段树

    2733: [HNOI2012]永无乡 Time Limit: 10 Sec  Memory Limit: 128 MB Description 永无乡包含 n 座岛,编号从 1 到 n,每座岛都有自 ...

  4. YSZOJ:#247. [福利]可持久化线段树 (最适合可持久化线段树入门)

    题目链接:https://syzoj.com/problem/247 解题心得: 可持久化线段树其实就是一个线段树功能的加强版,加强在哪里呢?那就是如果一颗普通的线段树多次修改之后还能知道最开始的线段 ...

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

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

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

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

  7. 【BZOJ】【3673】可持久化并查集 & 【3674】可持久化并查集加强版

    可持久化并查集 Orz hzwer & zyf 呃学习了一下可持久化并查集的姿势……其实并查集就是一个fa数组(可能还要带一个size或rank数组),那么我们对并查集可持久化其实就是实现一个 ...

  8. BZOJ 3674 可持久化并查集加强版(主席树变形)

    3673: 可持久化并查集 by zky Time Limit: 5 Sec  Memory Limit: 128 MB Submit: 2515  Solved: 1107 [Submit][Sta ...

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

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

随机推荐

  1. 【NOIP合并果子】uva 10954 add all【贪心】——yhx

    Yup!! The problem name reects your task; just add a set of numbers. But you may feel yourselvesconde ...

  2. NOIP2008提高组(前三题) -SilverN

    此处为前三题,第四题将单独发布 火柴棒等式 题目描述 给你n根火柴棍,你可以拼出多少个形如“A+B=C”的等式?等式中的A.B.C是用火柴棍拼出的整数(若该数非零,则最高位不能是0).用火柴棍拼数字0 ...

  3. mvc area区域和异步表单,bootstrap简单实例

    码农最怕眼高手低 今天来练习mvc Area技术和bootstrap以及异步表单的C#代码实现. 1.area区域架构对于建立复杂业务逻辑很有帮助,由  AreaRegistration.Regist ...

  4. jquery中的clone()方法使用

    clone([Even[,deepEven]]) 描述: 克隆匹配的DOM元素并且选中这些克隆的副本. 在想把DOM文档中元素的副本添加到其他位置时这个函数非常有用. 1:一个布尔值(true 或者 ...

  5. MySQL数据库学习笔记(十一)----DAO设计模式实现数据库的增删改查(进一步封装JDBC工具类)

    [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...

  6. Blend Tree Type

    1D 只有一个参数,用于控制状态之间的切换 2D Simple Directional 2D Simple Directional   :具有方向性的动画片段,同一方向上最好不要有多个动画片段 2D ...

  7. 在3D Max中查看模型引用的贴图

    需求 假如在Max中有一个模型,想查看贴图 操作步骤 1.右上角点击 2.在弹出材质编辑器中 点击吸管 3.把吸管点击在角色模型上,然后点击M 4.点击查看图像 5.就能查看到模型使用的贴图

  8. java 14-3 正则表达式的分割

    分割功能 String类的public String[] split(String regex) 根据给定正则表达式的匹配拆分此字符串. 例子: 可以用来做年龄段的筛选,比如说,我要筛选18-26之间 ...

  9. windows组件

    Wcript.shell是windows自带的组件 因为他过于强大 所以经常被黑客加以利用 他可以调用系统内核运行的dos基本命令 与此对应的还有三个危险组件 他们分别是 FSO shell.Appl ...

  10. 06Spring_使用注解配置bean对象

    Spring注解开发需要jar包 和 xml开发 一样的 ! 第一步: 新建项目, 导入jar包(就是前一篇文章里面的那几个核心jar包) 第二步: 在需要spring创建对象类上面 添加@Compo ...