#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int fa[maxn];
int nex[maxn]; // 表示下一个不是自己集合的位置
int find(int x){
return fa[x] == x ? fa[x]: fa[x] = find(fa[x]);
}
int main(){
int n,q;
cin>>n>>q;
for(int i = 0;i <= n;i++){
fa[i] = i;
nex[i] = i + 1;
}
while(q--){
int op,x,y;
cin>>op>>x>>y;
if(op == 1){
fa[find(x)] = find(y);
}else if(op == 2){
int to;
for(int i = x; i < y;i = to){ //通过nex数组 跳跃更新
fa[find(i)] = find(y);
to = nex[x];
nex[x] = nex[y];
}
}else{
if(find(x) == find(y)){
cout<<"YES\n";
}else{
cout<<"NO\n";
}
}
}
}
☀阳☀光☀开☀朗☀并☀查☀集☀
于 2023-11-13 18:38:44 首次发布