Submission #209607

#TimeUsernameProblemLanguageResultExecution timeMemory
209607stefdascaPort Facility (JOI17_port_facility)C++14
0 / 100
5 ms376 KiB
#include<bits/stdc++.h> #define god dimasi5eks #pragma GCC optimize("O3") #define fi first #define se second #define pb push_back #define pf push_front #define mod 1000000007 #define dancila 3.14159265359 #define eps 1e-9 // #define fisier 1 using namespace std; typedef long long ll; int n; pair<int, int> bk[1000002]; bool rau[1000002], maxi[2000002]; bool cmp(pair<int, int> a, pair<int, int> b) { if(a.se - a.fi == b.se - b.fi) return a.fi < b.fi; return a.se - a.fi < b.se - b.fi; } int main() { #ifdef fisier ifstream f("input.in"); ofstream g("output.out"); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for(int i = 1; i <= n; ++i) cin >> bk[i].fi >> bk[i].se; sort(bk + 1, bk + n + 1, cmp); int ans = 1; set<int> x; for(int i = 1; i <= n+n; ++i) x.insert(i); for(int i = 1; i <= n; ++i) { if(*x.upper_bound(bk[i].fi) == bk[i].se) { rau[bk[i].fi] = 1; ans = (ans * 2) % mod; x.erase(bk[i].fi); x.erase(bk[i].se); } } sort(bk + 1, bk + n + 1); x.clear(); int cntmax = 0; for(int i = 1; i <= n; ++i) { if(rau[bk[i].fi]) continue; while(!x.empty() && *x.begin() < bk[i].fi) { cntmax -= maxi[*x.begin()]; x.erase(x.begin()); } if(x.empty() && i != 1) ans = (ans * 2) % mod; if(x.empty() || *x.rbegin() < bk[i].se) { cntmax++; maxi[bk[i].se] = 1; } if(!x.empty() && bk[i].se < *x.begin()) ans = (ans * 2) % mod; x.insert(bk[i].se); if(cntmax >= 3) { cout << 0; return 0; } } if(!x.empty()) ans = (ans * 2) % mod; cout << ans; 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...