Submission #209612

#TimeUsernameProblemLanguageResultExecution timeMemory
209612stefdascaPort 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]; set<int> x, bs; 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; 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; int beg = 0; // cout << ans << '\n'; int str = 0; for(int i = 1; i <= n; ++i) { if(rau[bk[i].fi]) continue; while(!x.empty() && *x.begin() < bk[i].fi) { if(maxi[*x.begin()]) bs.clear(), str = 0; if(bs.find(*x.begin()) != bs.end()) bs.erase(*x.begin()), --str; cntmax -= maxi[*x.begin()]; x.erase(x.begin()); } if(x.empty() && beg) ans = (ans * 2) % mod; if(x.empty() || *x.rbegin() < bk[i].se) { cntmax++; maxi[bk[i].se] = 1; bs.clear(); while(str) ans = (ans * 500000004LL) % mod, --str; } if(!x.empty() && bk[i].se < *x.begin()) ans = (ans * 2) % mod, ++str, bs.insert(bk[i].se); x.insert(bk[i].se); beg = 1; if(cntmax >= 3) { cout << 0; return 0; } // cout << i << " " << ans << " " << str << '\n'; } 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...