Submission #1047726

#TimeUsernameProblemLanguageResultExecution timeMemory
1047726LoboJoker (BOI20_joker)C++17
100 / 100
158 ms13248 KiB
#include<bits/stdc++.h> using namespace std; const long long inf = 1e9 + 10; // #define int long long #define dbl long double #define endl '\n' #define sc second #define fr first #define mp make_pair #define pb push_back #define all(x) x.begin(), x.end() mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); const int maxn = 2e5+10; // L,R // (1,L) + (R,M) // (L+1,R-1) int n, m, q, isbip = 1, dsz[maxn], ans[maxn]; pair<int,int> ds[maxn], edg[maxn]; vector<pair<pair<int,int>,int>> roll; pair<int,int> find(int u) { if(ds[u].fr == u) return mp(u,0); auto aux = find(ds[u].fr); return mp(aux.fr,(ds[u].sc^aux.sc)); } void add(int i) { if(i == 0 or i == m+1) { roll.pb(mp(mp(0,0),0)); return; } int u = edg[i].fr; auto auxu = find(u); u = auxu.fr; int paru = auxu.sc; int v = edg[i].sc; auto auxv = find(v); v = auxv.fr; int parv = auxv.sc; if(u == v && paru == parv) { roll.pb(mp(mp(u,v),isbip)); isbip = 0; } else if(u != v) { if(dsz[u] < dsz[v]) { swap(u,v); swap(paru,parv); } roll.pb(mp(mp(u,v),isbip)); dsz[u]+= dsz[v]; ds[v].fr = u; ds[v].sc = (1^paru^parv); } else { roll.pb(mp(mp(u,v),isbip)); } } void rollback() { assert(roll.size()); if(roll.back().fr.fr == 0) { roll.pop_back(); return; } int u = roll.back().fr.fr; int v = roll.back().fr.sc; isbip = roll.back().sc; roll.pop_back(); if(u == v) return; ds[u] = mp(u,0); ds[v] = mp(v,0); dsz[u]-= dsz[v]; } // pra cada l, eu vejo qual o menor r em que // cada l, min r -> (1,l) + (r,m) eh bipartido // comeca sendo 0 m 1 m+1 // (5,7,1,2) pode acontecer (da certo pra tudo) void sol(int l1, int l2, int r1, int r2) { if(l1 > l2) return; int l = (l1+l2)/2; for(int i = l1+1; i <= l; i++) { add(i); } if(isbip == false) { for(int i = l; i <= l2; i++) { ans[i] = inf; } for(int i = l; i >= l1+1; i--) { rollback(); } sol(l1,l-1,r1,r2); return; } int r = r2; if(isbip == true) { while(r-1 >= r1) { r--; add(r); if(isbip == false) { rollback(); r++; break; } } } ans[l] = r; int R = r; while(r != r2) { r++; rollback(); } // r = r2 add(l+1); sol(l+1,l2,R,r2); for(int i = l+1; i >= l1+1; i--) { rollback(); } while(r != R) { r--; add(r); } // r = R sol(l1,l-1,r1,R); while(r != r2) { r++; rollback(); } // r = r2 } void solve() { cin >> n >> m >> q; for(int i = 1; i <= n; i++) { ds[i] = mp(i,0); dsz[i] = 1; } for(int i = 1; i <= m; i++) { int u,v; cin >> u >> v; edg[i] = mp(u,v); } isbip = 1; roll.pb(mp(mp(0,0),0)); roll.pb(mp(mp(0,0),0)); sol(0,m,1,m+1); for(int i = 1; i <= q; i++) { int l,r; cin >> l >> r; if(ans[l-1] <= r+1) { cout << "NO" << endl; } else { cout << "YES" << endl; } } } int32_t main() { ios::sync_with_stdio(false); cin.tie(0); #ifndef ONLINE_JUDGE // freopen("in.in", "r", stdin); // freopen("out.out", "w", stdout); #endif int tt = 1; // cin >> tt; while(tt--) { solve(); } }
#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...