# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
44407 | choikiwon | Port Facility (JOI17_port_facility) | C++17 | 2 ms | 376 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;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
const int MN = 1000010;
int N;
pii P[MN];
vector<int> A, B;
stack<set<int> > stk;
int main() {
scanf("%d", &N);
for(int i = 0; i < N; i++) {
scanf("%d %d", &P[i].first, &P[i].second);
}
sort(P, P + N);
for(int i = 0; i < N; i++) {
while(A.size() && A.back() < P[i].first) A.pop_back();
while(B.size() && B.back() < P[i].first) B.pop_back();
if(!A.size() || A.back() > P[i].second) {
A.push_back(P[i].second);
}
else if(!B.size() || B.back() > P[i].second) {
B.push_back(P[i].second);
}
else {
printf("0");
return 0;
}
}
int cnt = 0;
for(int i = 0; i < N; i++) {
while(!stk.empty() && *stk.top().rbegin() < P[i].first) {
stk.pop();
cnt++;
}
if(stk.empty()) {
stk.push(set<int>());
stk.top().insert(P[i].second);
}
else {
set<int>::iterator it = stk.top().lower_bound(P[i].first);
if(*it < P[i].second) {
stk.top().insert(P[i].second);
}
else {
stk.push(set<int>());
stk.top().insert(P[i].second);
}
}
}
while(!stk.empty()) {
stk.pop();
cnt++;
}
int ans = 1;
for(int i = 0; i < cnt; i++) ans = ans * 2 % mod;
printf("%d", 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... |