Submission #1000363

#TimeUsernameProblemLanguageResultExecution timeMemory
1000363AdamGSPort Facility (JOI17_port_facility)C++17
22 / 100
6068 ms52052 KiB
#include<bits/stdc++.h> using namespace std; typedef long double ld; typedef long long ll; #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 ll MOD=1e9+7; const int LIM=1e6+7; vector<int>V[LIM]; ll ans=1; pair<int,int>T[LIM]; int kol[LIM]; void DFS(int x, int o) { for(auto i : V[x]) { if(!kol[i]) { kol[i]=kol[x]^3; DFS(i, x); } else if(kol[i]==kol[x]) ans=0; } } int F[LIM], S[2*LIM], odw[LIM], sum[LIM]; int fnd(int x) { if(F[x]==x) return x; return F[x]=fnd(F[x]); } void uni(int a, int b) { if(fnd(a)==fnd(b)) return; F[fnd(b)]=fnd(a); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; rep(i, n) { cin >> T[i].st >> T[i].nd; --T[i].st; --T[i].nd; } sort(T, T+n); rep(i, n) rep(j, i) if(T[j].st<T[i].st && T[i].st<T[j].nd && T[j].nd<T[i].nd) { V[i].pb(j); V[j].pb(i); } rep(i, n) if(!kol[i]) { kol[i]=1; DFS(i, i); } rep(i, n) F[i]=i; rep(i, n) { S[T[i].st]=i+1; S[T[i].nd]=-i-1; } vector<int>P; rep(i, 2*n) { int p=abs(S[i])-1; if(S[i]>0) { P.pb(p); continue; } odw[p]=1; ++sum[P.back()]; --sum[p]; while(P.size()>0 && odw[P.back()]) { int x=P.back(); P.pop_back(); if(P.size()>0) { if(sum[x]) uni(x, P.back()); sum[P.back()]+=sum[x]; } } } rep(i, n) if(fnd(i)==i) ans=(ans*2)%MOD; cout << ans << '\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...