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 <iostream>
#include <cstdio>
#include <algorithm>
#include <array>
#include <stack>
#include <deque>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second
typedef array<deque<int>, 2> T;
const int mod = 1000000007;
const int mxn = 1000001;
int n, k;
pi a[mxn];
T stk[mxn / 2];
inline int f(int x){
return stk[k - 1][x].empty() ? 2 * n + 2 : stk[k - 1][x].front();
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i = 0; i < n; i++) cin >> a[i].f >> a[i].s;
a[n] = {2 * n + 1, 2 * n + 1};
sort(a, a + n);
int ret = 1;
for(int i = 0; i <= n; i++){
while(k){
for(int j = 0; j < 2; j++){
while(f(j) < a[i].f) stk[k - 1][j].pop_front();
}
if(f(0) > f(1)) swap(stk[k - 1][0], stk[k - 1][1]);
if(!stk[k - 1][0].empty()) break;
k--, (ret *= 2) %= mod;
}
if(!k || a[i].s < f(0)){
stk[k++][0].push_front(a[i].s);
}else{
while(k > 1 && stk[k - 1][1].empty()){
T x;
swap(stk[--k], x);
if(a[i].s < f(0)){
swap(stk[k++], x);
break;
}
if(x[0].size() < stk[k - 1][0].size()){
while(!x[0].empty()){
stk[k - 1][0].push_front(x[0].back());
x[0].pop_back();
}
}else{
swap(x[0], stk[k - 1][0]);
while(!x[0].empty()){
stk[k - 1][0].push_back(x[0].front());
x[0].pop_front();
}
}
}
if(a[i].s > f(1)){
ret = 0;
break;
}
stk[k - 1][1].push_front(a[i].s);
}
}
cout << ret << endl;
return 0;
}
# | 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... |