# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
77892 | win11905 | Port Facility (JOI17_port_facility) | C++11 | 6069 ms | 796360 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, col[N];
vector<pii> V;
vector<int> g[N];
void dfs(int u) {
for(int v : g[u]) if(!col[v]) col[v] = col[u] ^ 3, dfs(v);
else if(col[v] != (col[u] ^ 3)) cnt = -1e9;
}
int main() {
scanf("%d", &n);
V.reserve(n);
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) {
for(auto it = pos.lower_bound(V[i].x); it != pos.upper_bound(V[i].y); ++it) {
g[i].emplace_back(it->y), g[it->y].emplace_back(i);
}
pos[V[i].y] = i;
}
for(int i = 0; i < n; ++i) if(!col[i]) {
col[i] = 1, cnt++;
queue<int> Q; Q.emplace(i);
while(!Q.empty()) {
int now = Q.front(); Q.pop();
for(int v : g[now])
if(!col[v]) Q.emplace(v), col[v] = col[now] ^ 3;
else if(col[v] != (col[now] ^ 3)) cnt = -1e9;
}
}
if(cnt < 0) return puts("0"), 0;
int ans = 1;
for(int i = 0; i < cnt; ++i) ans = (ans << 1) % 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... |