#include "bits/stdc++.h"
using namespace std;
#ifdef duc_debug
#include "bits/debug.h"
#else
#define debug(...)
#endif
const int maxn = 2e6 + 6;
const int mod = 1e9 + 7;
int n, l[maxn], r[maxn];
int ord[maxn];
int lab[maxn];
int find(int u) {
return lab[u] < 0 ? u : lab[u] = find(lab[u]);
}
void join(int u, int v) {
u = find(u), v = find(v);
if (u == v) return;
if (lab[u] > lab[v]) swap(u, v);
lab[u] += lab[v];
lab[v] = u;
}
void solve() {
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> l[i] >> r[i];
}
iota(ord + 1, ord + n + 1, 1);
sort(ord + 1, ord + n + 1, [](const int &x, const int &y) -> bool {
return l[x] < l[y];
});
for (int i = 1; i <= n + n; ++i) {
lab[i] = -1;
}
set<pair<int, int>> s;
for (int i = 1; i <= n; ++i) {
auto ft = s.lower_bound(make_pair(l[ord[i]], -1));
auto se = s.lower_bound(make_pair(r[ord[i]], -1));
if (se != s.begin() and se != ft) {
se--;
while (ft != s.end()) {
join(ord[i] + n, ft->second);
join(ord[i], ft->second + n);
if (find(ft->second) == find(se->second)) break;
++ft;
}
}
s.insert(make_pair(r[ord[i]], ord[i]));
}
int ans = 1;
for (int i = 1; i <= n; ++i) {
if (find(i) == find(i + n)) {
cout << 0;
return;
}
if (lab[i] < 0) {
ans = ans + ans;
if (ans >= mod) ans -= mod;
}
}
cout << ans;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
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... |