제출 #244199

#제출 시각아이디문제언어결과실행 시간메모리
244199Osama_AlkhodairyPort Facility (JOI17_port_facility)C++17
0 / 100
5 ms384 KiB
#include <bits/stdc++.h> using namespace std; #define finish(x) return cout << x << endl, 0 #define ll long long int n, mod = 1e9 + 7; vector <int> a; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; a.resize(2 * n); vector <int> l(n + 1), r(n + 1); for(int i = 1 ; i <= n ; i++){ cin >> l[i] >> r[i]; l[i]--; r[i]--; a[l[i]] = i; a[r[i]] = -i; } int ans = 0; vector <int> vis(n + 1); vector <int> g, h; for(auto &i : a){ if(i < 0){ i *= -1; if(h.size() && h.back() == i){ h.pop_back(); for(int j = (int)g.size() - 1 ; j >= 0 ; j--){ if(l[g[j]] > l[i]) ans--; else break; } continue; } vector <int> c; while(g.size() && g.back() != i){ c.push_back(g.back()); g.pop_back(); } if(g.size() == 0) finish(0); g.pop_back(); reverse(c.begin(), c.end()); for(auto &i : c){ ans--; h.push_back(i); } } else{ g.push_back(i); ans++; } } int res = 1; while(ans--){ res *= 2; if(res >= mod) res -= mod; } cout << res << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...