제출 #337286

#제출 시각아이디문제언어결과실행 시간메모리
337286super_j6Port Facility (JOI17_port_facility)C++14
78 / 100
1112 ms1048580 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...