# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
129853 | nikolapesic2802 | Port Facility (JOI17_port_facility) | C++14 | 9 ms | 8184 KiB |
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;
#define pii pair<int, int>
#define x first
#define y second
const int N = 1e6+5;
const int M = 1e9+7;
int n, cnt, dsu[N<<1];
vector<pii> V;
int find(int x) { return dsu[x] = dsu[x] == x ? x : find(dsu[x]);}
void mge(int x, int y) { dsu[find(x)] = find(y); }
int main() {
scanf("%d", &n);
V.reserve(n);
iota(dsu, dsu+2*N, 0);
for(int i = 0, a, b; i < n; ++i) scanf("%d %d", &a, &b), V.emplace_back(a, b);
sort(V.begin(), V.end());
map<int, int> pos;
for(int i = 0; i < n; ++i) {
auto it = pos.lower_bound(V[i].x), zz = pos.upper_bound(V[i].y);
bool st = it != zz;
if(zz != pos.begin()) zz--;
if(st) for(;; ++it) {
mge(i, it->y+n), mge(i+n, it->y);
if(find(it->y) == find(zz->y)) break;
if(it == zz) break;
}
pos[V[i].y] = i;
}
for(int i = 0; i < n; ++i) if(find(i) == find(i+n)) return puts("0"), 0;
int ans = 1;
for(int i = 0; i < 2*n; ++i) if(find(i) == i) ans = ans * 2 % M;
printf("%d\n", ans);
}
Compilation message (stderr)
# | 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... |