1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| #include<iostream> #include<cstdio> #include<vector> #define ll long long using namespace std; namespace Ehnaev{ inline ll read() { ll ret=0,f=1;char ch=getchar(); while(ch<48||ch>57) {if(ch==45) f=-f;ch=getchar();} while(ch>=48&&ch<=57) {ret=(ret<<3)+(ret<<1)+ch-48;ch=getchar();} return ret*f; } inline void write(ll x) { static char buf[22];static ll len=-1; if(x>=0) {do{buf[++len]=x%10+48;x/=10;}while(x);} else {putchar(45);do{buf[++len]=-(x%10)+48;x/=10;}while(x);} while(len>=0) putchar(buf[len--]); } }using Ehnaev::read;using Ehnaev::write;
const ll N=1e6;
ll n,m,k,top; ll fa[N+5],d[N+5];
struct Qry{ll l,r,u,v;}q[N+5];
struct Opt{ ll x,val; inline Opt() {}; inline Opt(ll a,ll b):x(a),val(b) {} }st[N+5];
struct Edge{ ll u,v; inline Edge() {} inline Edge(ll a,ll b):u(a),v(b) {} }; vector<Edge> e[N+5];
inline void Add(ll p,ll lp,ll rp,ll l,ll r,ll u,ll v) { if(lp>=l&&rp<=r) {e[p].push_back(Edge(u,v));return;} ll mid=(lp+rp)>>1; if(l<=mid) Add(p<<1,lp,mid,l,r,u,v); if(r>mid) Add(p<<1|1,mid+1,rp,l,r,u,v); }
inline void Revo() { ll x=st[top].x,val=st[top].val;d[fa[x]]=val;fa[x]=x;top--; }
inline ll Get(ll x) { if(x==fa[x]) return x;d[fa[x]]=max(d[fa[x]],d[x]+1);return Get(fa[x]); }
inline void Merge(ll x,ll y) { ll u=Get(x),v=Get(y);if(d[u]<d[v]) swap(u,v); st[++top]=Opt(v,d[u]);fa[v]=u;d[u]=max(d[v]+1,d[u]); }
inline void Dfs(ll p,ll lp,ll rp) { ll flg=0,pos=top; for(ll i=0;i<(ll)e[p].size();i++) { ll a=e[p][i].u,b=e[p][i].v; if(Get(a)==Get(b)) {flg=i+1;break;} Merge(a,b+n);Merge(a+n,b); } if(flg) {for(ll i=lp;i<=rp;i++) {printf("No\n");}} else { if(lp==rp) {printf("Yes\n");} else {ll mid=(lp+rp)>>1;Dfs(p<<1,lp,mid);Dfs(p<<1|1,mid+1,rp);} } while(top>pos) {ll x=st[top].x;d[fa[x]]=st[top].val;fa[x]=x;top--;} }
int main() {
n=read();m=read();k=read(); for(ll i=1;i<=2*n;i++) fa[i]=i;
for(ll i=1;i<=m;i++) { q[i].u=read();q[i].v=read();q[i].l=read();q[i].r=read(); Add(1,1,k,q[i].l+1,q[i].r,q[i].u,q[i].v); }
Dfs(1,1,k);
return 0; }
|