제출 #77730

#제출 시각아이디문제언어결과실행 시간메모리
77730szawinisPort Facility (JOI17_port_facility)C++17
22 / 100
6098 ms26592 KiB
#include <bits/stdc++.h> #define long long long using namespace std; const long MOD = 1e9+7; const int N = 1 << 21; struct seg { int l, r, i; seg() { l = r = i = MOD; } seg(int l, int r, int i): l(l), r(r), i(i) {} seg(int r): r(r) { l = i = MOD; } bool operator<(const seg& rhs) const { return r < rhs.r; } }; int n; vector<seg> a; set<seg> st; int dsu[N]; int root(int v) { return (dsu[v] < 0 ? v : dsu[v] = root(dsu[v])); } void merge(int u, int v) { if((u = root(u)) == (v = root(v))) return; dsu[u] += dsu[v]; dsu[v] = u; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for(int i = 0, x, y; i < n; i++) { cin >> x >> y; a.emplace_back(x, y, i); } fill(dsu, dsu+N, -1); sort(a.begin(), a.end(), [] (seg x, seg y) { return x.l < y.l; }); for(seg s: a) { while(!st.empty() && st.begin()->r < s.l) st.erase(st.begin()); auto ed = st.upper_bound(seg(s.r)); if(st.empty() || ed == st.begin()) { st.insert(s); continue; } for(auto it = st.begin(); it != ed; it++) { int u = it->i, v = s.i; merge(u, v + n); merge(u + n, v); } st.insert(s); } for(int i = 0; i < n; i++) if(root(i) == root(i + n)) cout << 0, exit(0); long ans = 1; for(int i = 0; i < n; i++) if(root(i) == i) ans = ans * 2 % MOD; cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...