This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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[2000000], n;
int find(int A) {
while (A != cmp[A]) cmp[A] = cmp[cmp[A]], A = cmp[A];
return A;
}
bool onion(int A, int B) { cmp[find(A)] = find(B); }
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
FOR(i, 0, n) cin >> a[i].first >> a[i].second;
sort(a, a + n);
iota(cmp, cmp + 2 * n, 0);
set<pair<int, int>> s;
FOR(i, 0, n) {
while (s.size() && (*s.begin()).first < a[i].first) s.erase(s.begin());
auto ub = s.upper_bound({a[i].second, n});
if (ub != s.begin())
for (ub--;; ub--) {
onion(i, (*ub).second + n);
onion(i + n, (*ub).second);
if (find((*ub).second) == find((*s.begin()).second)) break;
if (ub == s.begin()) break;
}
s.insert({a[i].second, i});
}
FOR(i, 0, n) if (find(i) == find(i + n)) return cout << 0, 0;
ll cnt = 0, ans = 1;
FOR(i, 0, 2 * n) if (find(i) == i) cnt++;
FOR(i, 0, cnt / 2) ans = (ans * 2) % MOD;
cout << ans;
return 0;
}
Compilation message (stderr)
port_facility.cpp: In function 'bool onion(int, int)':
port_facility.cpp:16:52: warning: no return statement in function returning non-void [-Wreturn-type]
bool onion(int A, int B) { cmp[find(A)] = find(B); }
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |