이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
pi a[mxn];
stack<T> stk;
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;
stk.push(T());
for(int i = 0; i < 2; i++) stk.top()[i].push_front(2 * n + 2);
for(int i = 0; i <= n; i++){
while(1){
for(int j = 0; j < 2; j++){
while(stk.top()[j].front() < a[i].f) stk.top()[j].pop_front();
}
if(stk.top()[0].front() > stk.top()[1].front()){
swap(stk.top()[0], stk.top()[1]);
}
if(stk.top()[0].front() < 2 * n + 3) break;
stk.pop(), (ret *= 2) %= mod;
}
if(a[i].s < stk.top()[0].front()){
stk.push(T());
for(int j = 0; j < 2; j++) stk.top()[j].push_front(2 * n + 3);
stk.top()[0].push_front(a[i].s);
}else{
T x;
while(stk.size() > 2 && stk.top()[1].front() == 2 * n + 3){
swap(stk.top(), x);
stk.pop();
if(a[i].s < stk.top()[0].front()){
stk.push(T());
swap(stk.top(), x);
break;
}
x[0].pop_back();
if(x[0].size() < stk.top()[0].size()){
while(!x[0].empty()){
stk.top()[0].push_front(x[0].back());
x[0].pop_back();
}
}else{
swap(x[0], stk.top()[0]);
while(!x[0].empty()){
stk.top()[0].push_back(x[0].front());
x[0].pop_front();
}
}
}
if(a[i].s < stk.top()[1].front()){
stk.top()[1].push_front(a[i].s);
}else{
ret = 0;
break;
}
}
}
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... |