洛谷P5787
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const LL MAXN=1e6+5;
LL n,m,k;
pair<LL,LL>e[MAXN];
struct node{
LL x,y,add;
};
node stk[MAXN];
vector<LL>tr[MAXN];
LL fa[MAXN],hei[MAXN],top;
LL find(LL x){
while(x!=fa[x])x=fa[x];
return fa[x];
}
void merge(LL x,LL y){
LL fx=find(x),fy=find(y);
if(hei[fx]>hei[fy])swap(fx,fy);
stk[++top]=(node){fx,fy,hei[fx]==hei[fy]};
fa[fx]=fy;
if(hei[fx]==hei[fy])hei[fy]++;
}
void update(LL rt,LL l,LL r,LL L,LL R,LL x){
if(l>R||r<L)return ;
else if(L<=l&&r<=R){
tr[rt].push_back(x);
return ;
}else{
LL mid=(l+r)>>1;
update(rt<<1,l,mid,L,R,x);
update(rt<<1|1,mid+1,r,L,R,x);
}
}
void solve(LL rt,LL l,LL r){
LL ans=1,lasttop=top;
for(LL i=0;i<tr[rt].size();i++){
LL xx=find(e[tr[rt][i]].first);
LL yy=find(e[tr[rt][i]].second);
if(xx==yy){
for(LL j=l;j<=r;j++){
printf("No\n");
}
ans=0;
break;
}
merge(e[tr[rt][i]].first,e[tr[rt][i]].second+n);
merge(e[tr[rt][i]].second,e[tr[rt][i]].first+n);
}
if(ans){
if(l==r)printf("Yes\n");
else{
LL mid=(l+r)>>1;
solve(rt<<1,l,mid);
solve(rt<<1|1,mid+1,r);
}
}
while(top>lasttop){
hei[fa[stk[top].y]]-=stk[top].add;
fa[stk[top].x]=stk[top].x;
top--;
}
}
int main(){
scanf("%lld%lld%lld",&n,&m,&k);
for(LL i=1;i<=m;i++){
scanf("%lld%lld",&e[i].first,&e[i].second);
LL l,r;
scanf("%lld%lld",&l,&r);
l++;
update(1,1,k,l,r,i);
}
for(LL i=1;i<=2*n;i++){
fa[i]=i;hei[i]=1;
}
solve(1,1,k);
}