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[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\n", 0;
}
s.insert({a[i].second, i});
}
ll ans = 1;
FOR(i, 0, cnt) ans = (ans * 2) % MOD;
cout << ans << '\n';
return 0;
}
# | 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... |