# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
28211 | top34051 | Port Facility (JOI17_port_facility) | C++14 | 2013 ms | 74152 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 maxn 1000005
#define mod 1000000007LL
int n;
int head[maxn*2];
bool check[maxn*2];
pair<int,int> p[maxn];
map<int,int> pos;
int findhead(int x) {
if(x==head[x]) return x;
return head[x] = findhead(head[x]);
}
void fus(int x,int y) {
head[findhead(x)] = findhead(y);
}
main() {
int i;
long long ans;
map<int,int>::iterator st,ft;
scanf("%d",&n);
for(i=0;i<n;i++) scanf("%d%d",&p[i].first,&p[i].second);
sort(&p[0],&p[n]);
for(i=0;i<n*2;i++) head[i] = i;
for(i=0;i<n;i++) {
st = pos.lower_bound(p[i].first);
ft = pos.lower_bound(p[i].second);
while(st!=ft) {
fus(i,st->second+n); fus(i+n,st->second);
if(findhead(st->second)==findhead((--ft)->second)) break;
++ft;
st++;
}
pos[p[i].second] = i;
}
ans = 1;
for(i=0;i<n;i++) {
if(findhead(i)==findhead(i+n)) ans = 0;
else check[findhead(i)] = check[findhead(i+n)] = 1;
}
for(i=0;i<n;i++) if(check[i]) ans = (ans*2)%mod;
printf("%lld",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... |