Submission #684550

#TimeUsernameProblemLanguageResultExecution timeMemory
684550uroskJoker (BOI20_joker)C++14
0 / 100
1 ms340 KiB
#define here cerr<<"===========================================\n" #define dbg(x) cerr<<#x<<": "<<x<<endl; #include "bits/stdc++.h" //#include <ext/pb_ds/tree_policy.hpp> //#include <ext/pb_ds/assoc_container.hpp> #define ld double #define ll long long #define llinf 100000000000000000LL // 10^17 #define pb push_back #define popb pop_back #define fi first #define sc second #define endl '\n' #define pll pair<ll,ll> #define pld pair<ld,ld> #define sz(a) (ll)(a.size()) #define all(a) a.begin(),a.end() #define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;} #define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;} #define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0); using namespace std; //using namespace __gnu_pbds; /* ll add(ll x,ll y){ x+=y; if(x<0){ x%=mod; x+=mod; }else{ if(x>=mod) x%=mod; } return x; } ll mul(ll a,ll b){ ll ans = (a*b)%mod; if(ans<0) ans+=mod; return ans; } typedef tree<int,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; typedef tree<int,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll rnd(ll l,ll r){ return uniform_int_distribution<ll>(l,r)(rng); } */ #define maxn 200005 ll n,m,q; pll e[maxn]; ll dsu[maxn],sizi[maxn]; ll last[maxn]; ll root(ll x){ while(x!=dsu[x]) x = dsu[x]; return x; } ll col(ll x){ ll cnt = 0; while(x!=dsu[x]){cnt++;x = dsu[x];} return cnt&1; } stack<pll> st; ll cnt = 0; void upd(ll u,ll v){ u = root(u); v = root(v); if(sizi[u]>sizi[v]) swap(u,v); if(u==v){ if(col(u)==col(v)) cnt++; }else{ sizi[u]+=sizi[v]; dsu[v] = u; } st.push({v,u}); } void roll(){ if(st.empty()) here; ll v = st.top().fi; ll u = st.top().sc; if(dsu[v]==u){ st.pop(); sizi[u]-=sizi[v]; dsu[v] = v; }else{ if(col(u)==col(v)) cnt--; } } void reshi(ll l,ll r,ll tl,ll tr){ if(l>r) return; ll mid = (l+r)/2; for(ll i = l;i<mid;i++){ upd(e[i].fi,e[i].sc); } ll i = tr; if(cnt) last[mid] = m+1; while(!cnt&&i>=max(mid+1,tl)){ upd(e[i].fi,e[i].sc); i--; } for(ll j = i+2;j<=tr;j++) roll(); if(!last[mid]) last[mid] = i; //cerr<<cnt<< " "<<l<< " "<<r<< " "<<tl<< " "<<tr<<" "<<i<<endl; reshi(mid+1,r,max(mid+1,i),tr); for(ll j = l;j<mid;j++) roll(); for(ll j = i+1;j<=tr;j++) upd(e[j].fi,e[j].sc); reshi(l,mid-1,tl,i); } void tc(){ cin >> n >> m >> q; for(ll i = 1;i<=m;i++) cin >> e[i].fi >> e[i].sc; iota(dsu+1,dsu+1+n,1); reshi(1,m,1,m); //ceri(last,1,n); while(q--){ ll l,r; cin >> l >> r; if(last[l]>=r) cout<<"YES"<<endl; else cout<<"NO"<<endl; } } int main(){ daj_mi_malo_vremena int t; t = 1; while(t--){ tc(); } return 0; }
#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...