记录: https://darkbzoj.cc/submission/262818
https://www.luogu.com.cn/record/174105607
code:
#include<bits/stdc++.h>
using namespace std;
const int N = 200005;
struct{
int x;
int y;
}a[N << 2];
struct node{
int x;
int y;
int r;
}s[N << 6];
int top = 0;
int n,m,k;
namespace Set{
int f[N << 2],r[N << 2];
void init(int n){
for(int i = 1;i <= n;++ i){
f[i] = i;
r[i] = 1;
}
}
int find(int w){
if(f[w] == w) return w;
return find(f[w]);
}
void merge(int x,int y){
x = find(x),y = find(y);
if(x == y) return;
if(r[x] > r[y]) swap(x,y);
top ++;
s[top] = {x,y,r[x]};
r[y] += r[x];
f[x] = y;
}
bool cancel(const node& w){
int x = w.x;
int y = w.y;
int z = w.r;
r[f[x]] -= z;
f[x] = x;
}
bool insert(int w){
int x = a[w].x;
int y = a[w].y;
int fx = find(x),fy = find(y),fxn = find(x + n),fyn = find(y + n);
if(fx == fy || fxn == fyn) return false;
merge(fx,fyn);
merge(fy,fxn);
return true;
}
}
bool used[N << 2];
namespace SegTree{
#define l(p) t[(p)].l
#define r(p) t[(p)].r
#define data(p) t[(p)].data
#define lc(p) ((p) << 1)
#define rc(p) ((p) << 1 | 1)
struct node{
int l;
int r;
vector<int> data;
}t[N << 2];
void build(int p,int l,int r){
l(p) = l;
r(p) = r;
if(l == r) return;
int mid = (l + r) >> 1;
build(lc(p),l,mid);
build(rc(p),mid + 1,r);
}
void change(int p,int l,int r,int x){
if(l > r) return;
if(l <= l(p) && r >= r(p)){
data(p).push_back(x);
return;
}
int mid = (l(p) + r(p)) >> 1;
if(l <= mid) change(lc(p),l,r,x);
if(r > mid) change(rc(p),l,r,x);
}
int cnt = 0;
void inorder(int p){
if(!l(p)) return;
if(!p) return;
int last = top;
int len = data(p).size();
for(int z = 0;z < len;++ z){
int x = data(p)[z];
if(!Set::insert(x)){
for(int i = l(p);i <= r(p);++ i) cout<<"No\n";
while(last != top){
Set::cancel(s[top]);
top --;
}
return;
}
}
if(l(p) == r(p)){
if(l(p) <= k) cout<<"Yes\n";
while(last != top){
Set::cancel(s[top]);
top --;
}
return;
}
inorder(lc(p));
inorder(rc(p));
while(last != top){
Set::cancel(s[top]);
top --;
}
}
}
int main(){
// freopen("4025/1.in","r",stdin);
// freopen("out.txt","w",stdout);
// cout<<sizeof(s) / 1024 / 1024;
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>m>>k;
SegTree::build(1,1,k);
Set::init((n << 1) + 5);
for(int i = 1;i <= m;++ i){
int l,r;
cin>>a[i].x>>a[i].y>>l>>r;
if(l == r) continue;
SegTree::change(1,l + 1,r,i);
}
SegTree::inorder(1);
return 0;
}