Submission #963697

#TimeUsernameProblemLanguageResultExecution timeMemory
963697CookiePort Facility (JOI17_port_facility)C++14
100 / 100
2912 ms140992 KiB
#include<bits/stdc++.h> #include<fstream> using namespace std; #define sz(a) (int)a.size() #define ALL(v) v.begin(), v.end() #define ALLR(v) v.rbegin(), v.rend() #define ll long long #define pb push_back #define forr(i, a, b) for(int i = a; i < b; i++) #define dorr(i, a, b) for(int i = a; i >= b; i--) #define ld long double #define vt vector #include<fstream> #define fi first #define se second #define pll pair<ll, ll> #define pii pair<int, int> #define mpp make_pair const ld PI = 3.14159265359, prec = 1e-9;; //using u128 = __uint128_t; //const int x[4] = {1, 0, -1, 0}; //const int y[4] = {0, -1, 0, 1}; const ll mod = 1e9 + 7, pr = 31; const int mxn = 1e6 + 5, mxq = 1e5 + 5, sq = 500, mxv = 5e4 + 1; //const int base = (1 <<18); const ll inf = 1e9 + 5, neg = -69420, inf2 = 1e14; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); // have fun! //JOIIIIIIIIIIIIIII int n; pii p[mxn + 1]; int c[mxn + 1]; int st[8 * mxn + 1], st2[8 * mxn + 1]; void upd(int nd, int l, int r, int id, int v){ if(l == r){ st[nd] = v; return; } int mid = (l + r) >> 1; if(id <= mid)upd(nd << 1, l, mid, id, v); else upd(nd << 1 | 1, mid + 1, r, id, v); int cand1 = st[nd << 1], cand2 = st[nd << 1 | 1]; st[nd] = ((p[cand1].se > p[cand2].se) ? cand1: cand2); } void upd2(int nd, int l, int r, int id, int v){ if(l == r){ st2[nd] = v; return; } int mid = (l + r) >> 1; if(id <= mid)upd2(nd << 1, l, mid, id, v); else upd2(nd << 1 | 1, mid + 1, r, id, v); int cand1 = st2[nd << 1], cand2 = st2[nd << 1 | 1]; st2[nd] = ((p[cand1].fi < p[cand2].fi) ? cand1: cand2); } int get(int nd, int l, int r, int ql, int qr){ if(ql > r || qr < l)return(0); if(ql <= l && qr >= r)return(st[nd]); int mid = (l + r) >> 1; int cand1 = get(nd << 1, l, mid, ql, qr), cand2 = get(nd << 1 | 1, mid + 1, r, ql, qr); return((p[cand1].se > p[cand2].se) ? cand1 : cand2); } int get2(int nd, int l, int r, int ql, int qr){ if(ql > r || qr < l)return(0); if(ql <= l && qr >= r)return(st2[nd]); int mid = (l + r) >> 1; int cand1 = get2(nd << 1, l, mid, ql, qr), cand2 = get2(nd << 1 | 1, mid + 1, r, ql, qr); return((p[cand1].fi < p[cand2].fi) ? cand1 : cand2); } void dfs(int s){ upd(1, 1, 2 * n, p[s].fi, 0); upd2(1, 1, 2 * n, p[s].se, 0); while(1){ int v = get(1, 1, 2 * n, p[s].fi, p[s].se); if(p[v].se > p[s].se){ c[v] = c[s] ^ 1; dfs(v); }else{ break; } } while(1){ int v = get2(1, 1, 2 * n, p[s].fi, p[s].se); if(p[v].fi < p[s].fi){ c[v] = c[s] ^ 1; dfs(v); }else{ break; } } } void solve(){ cin >> n; p[0].fi = inf; p[0].se = 0; for(int i = 1; i <= n; i++)cin >> p[i].fi >> p[i].se; sort(p + 1, p + n + 1); for(int i = 1; i <= n; i++){ upd(1, 1, 2 * n, p[i].fi, i); upd2(1, 1, 2 * n, p[i].se, i); } int cnt = 0; for(int i = 1; i <= n; i++)c[i] = -1; for(int i = 1; i <= n; i++){ if(c[i] == -1){ c[i] = 0; dfs(i); ++cnt; } } set<int>s1, s2; for(int i = 1; i <= n; i++){ if(c[i] == 0){ auto it = s1.lower_bound(p[i].fi); if(it == s1.end() || (*it) > p[i].se){ s1.insert(p[i].se); }else{ cout << 0; return; } }else{ auto it = s2.lower_bound(p[i].fi); if(it == s2.end() || (*it) > p[i].se){ s2.insert(p[i].se); }else{ cout << 0; return; } } } int ans = 1; for(int i = 0; i < cnt; i++)ans = (ans * 2) % mod; cout << ans; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("DATA.inp", "r", stdin); //freopen("DATA.out", "w", stdout); int tt; tt = 1; while(tt--){ solve(); } 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...