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>
using namespace std;
using ll = long long;
#define pii pair<int, int>
const int maxn = 1000010;
int mod = 1000000007;
int N;
ll ans, inv2;
vector<pii> vals;
int par[maxn*2];
int findset(int u) {
if (par[u] == u) return u;
return par[u] = findset(par[u]);
}
void unionset(int a, int b) {
a = findset(a);
b = findset(b);
if (a != b) {
par[a] = b;
}
}
map<int, int> mp;
bool used[maxn*2];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N;
int a, b;
for (int i = 0; i < N; i++) {
cin >> a >> b;
vals.push_back(pii(a, b));
}
sort(vals.begin(), vals.end());
for (int i = 0; i < 2*N; i++) {
par[i] = i;
}
for (int i = 0; i < N; i++) {
a = vals[i].first;
b = vals[i].second;
auto fi = mp.lower_bound(a), se = mp.lower_bound(b);
while (fi != se) {
unionset(i, (fi -> second) + N);
unionset(i + N, fi -> second);
if (findset((--se) -> second) == findset(fi -> second)) {
break;
}
++fi;
++se;
}
mp[b] = i;
}
ans = 1;
for (int i = 0; i < N; i++) {
if (findset(i) == findset(i+N)) ans = 0;
used[findset(i)] = true;
used[findset(i+N)] = true;
}
for (int i = 0; i < N; i++) {
if (used[i]) ans = (ans*2LL)%mod;
}
cout << ans << endl;
}
# | 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... |