제출 #622378

#제출 시각아이디문제언어결과실행 시간메모리
622378HanksburgerPort Facility (JOI17_port_facility)C++17
100 / 100
1476 ms89200 KiB
#include <bits/stdc++.h> using namespace std; const int mod=1e9+7; pair<int, int> a[1000005]; set<pair<int, int> > s; int p[2000005]; int par(int x) { return p[x]==x?x:(p[x]=par(p[x])); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, ans=1; cin >> n; for (int i=1; i<=n; i++) cin >> a[i].first >> a[i].second; sort(a+1, a+n+1); for (int i=1; i<=n*2; i++) p[i]=i; for (int i=1; i<=n; i++) { auto itr1=s.lower_bound({a[i].first, 0}), itr2=s.lower_bound({a[i].second, 0}); for (auto itr=itr1; itr!=itr2; itr++) { p[par(itr->second+n)]=par(i); p[par(itr->second)]=par(i+n); if (par(itr->second)==par(prev(itr2)->second)) break; } s.insert({a[i].second, i}); } for (int i=1; i<=n; i++) { if (par(i)==par(i+n)) { cout << 0; return 0; } } for (int i=1; i<=n; i++) if (par(i)==i) ans=ans*2%mod; cout << '\n'; cout << ans; 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...