Submission #210425

#TimeUsernameProblemLanguageResultExecution timeMemory
210425dolphingarlicPort Facility (JOI17_port_facility)C++14
0 / 100
5 ms376 KiB
#include <bits/stdc++.h> #define FOR(i, x, y) for (int i = x; i < y; i++) typedef long long ll; using namespace std; const ll MOD = 1e9 + 7; pair<int, int> a[1000000]; int cmp[1000000], cnt; int find(int A) { while (A != cmp[A]) cmp[A] = cmp[cmp[A]], A = cmp[A]; return A; } bool onion(int A, int B) { A = find(A), B = find(B); if (A == B) return false; cmp[A] = B; cnt--; return true; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; FOR(i, 0, n) cin >> a[i].first >> a[i].second; sort(a, a + n); cnt = n; iota(cmp, cmp + n, 0); set<pair<int, int>> s; FOR(i, 0, n) { while (s.size() && (*s.begin()).first < a[i].first) s.erase(s.begin()); for (pair<int, int> j : s) { if (j.first > a[i].second) break; if (!onion(i, j.second)) return cout << 0, 0; } s.insert({a[i].second, i}); } ll ans = 1; FOR(i, 0, cnt) ans = (ans * 2) % MOD; 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...