Submission #480052

#TimeUsernameProblemLanguageResultExecution timeMemory
480052AdamGSJoker (BOI20_joker)C++14
0 / 100
89 ms9528 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() const int LIM=2e5+7; struct operacje { int a, ilea, kolora, b, ileb, kolorb, zmianacyklu; }; pair<int,int>F[LIM], kraw[LIM]; int ile[LIM], T[LIM], cykl; stack<operacje>S; pair<int,int>fnd(int x) { if(F[x].st==x) return F[x]; pair<int,int>ans=fnd(F[x].st); ans.nd^=F[x].nd; return ans; } void uni(int a, int b) { pair<int,int>x=fnd(a), y=fnd(b); operacje p={x.st, ile[x.st], x.nd, y.st, ile[y.st], y.nd, 0}; if(x.st==y.st) { if(x.nd==y.nd) { ++cykl; p.zmianacyklu=1; } S.push(p); return; } if(ile[x.st]>ile[y.st]) swap(x, y); ile[y.st]+=ile[x.st]; F[x.st]={y.st, x.nd==y.nd}; S.push(p); } void usun(int x) { while(x--) { operacje p=S.top(); S.pop(); F[p.a]={p.a, p.kolora}; ile[p.a]=p.ilea; F[p.b]={p.b, p.kolorb}; ile[p.b]=p.ileb; cykl-=p.zmianacyklu; } } void dodaj(int l, int r) { while(l<=r) { uni(kraw[l].st, kraw[l].nd); ++l; } } void dc(int l, int r, int a, int b) { int mid=(l+r)/2, p=b+1; dodaj(l, mid-1); while(!cykl) { --p; dodaj(p, p); } usun(b-p+1); if(l==r) { T[l]=p; return; } usun(mid-l); dodaj(p+1, b); dc(l, mid, a, min(p, b)); usun(max(0, b-p)); dodaj(l, mid); dc(mid+1, r, min(p, b), b); usun(mid-l+1); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, q; cin >> n >> m >> q; rep(i, n) { F[i]={i, 0}; ile[i]=1; } rep(i, m) { cin >> kraw[i].st >> kraw[i].nd; --kraw[i].st; --kraw[i].nd; } dodaj(0, m-1); if(!cykl) { while(q--) cout << "NO\n"; return 0; } usun(m); T[0]=m; while(!cykl) { dodaj(T[0], T[0]); --T[0]; } while(q--) { int a, b; cin >> a >> b; --a; --b; cout << (b<T[a]?"YES":"NO") << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...