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 long long long
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const int N = 1e5+5;
const int M = 1e9+7;
int par[N << 1];
int find(int x) { return par[x] = x == par[x] ? x : find(par[x]); }
long modpow(long a, long b) {
long ret = 1;
for( ; b; b >>= 1) {
if(b & 1) ret = (ret * a) % M;
a = (a * a) % M;
}
return ret;
}
struct item {
int x, y, idx;
item(int x, int y, int idx) : x(x), y(y), idx(idx) { }
friend bool operator<(const item &a, const item &b) {
return a.y < b.y;
}
};
int n;
vector<item> vec;
set<item> S;
int main() {
iota(par, par + (N << 1), 0);
scanf("%d", &n);
for(int i = 1, x, y; i <= n; i++) {
scanf("%d %d", &x, &y);
vec.emplace_back(x, y, i);
}
sort(vec.begin(), vec.end(), [&](const item &a, const item &b) {
return a.x < b.x;
});
for(item now : vec) {
while(!S.empty() && S.begin()->y < now.x) S.erase(S.begin());
auto f = S.upper_bound(item(0, now.y, 0));
if(!S.empty()) for(auto it = S.begin(); it != f; it++) {
int u = now.idx, v = it->idx;
par[find(u + n)] = find(v);
par[find(v)] = find(u + n);
if(find(v) == find(prev(f)->idx)) break;
}
S.emplace(now);
}
int cnt = 0;
for(int i = 1; i <= n; i++) {
if(find(i) == find(i + n)) return !printf("0\n");
if(find(i) == i) ++cnt;
}
printf("%lld\n", modpow(2, cnt));
return 0;
}
Compilation message (stderr)
port_facility.cpp: In function 'int main()':
port_facility.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
port_facility.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &x, &y);
~~~~~^~~~~~~~~~~~~~~~~
# | 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... |