Submission #537061

#TimeUsernameProblemLanguageResultExecution timeMemory
537061cig32Port Facility (JOI17_port_facility)C++17
22 / 100
6087 ms283656 KiB
#include "bits/stdc++.h" using namespace std; const int MAXN = 2e6 + 10; const int MOD = 1e9 + 7; #define int long long mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count()); int rnd(int x, int y) { int u = uniform_int_distribution<int>(x, y)(rng); return u; } long long bm(long long b, long long p) { if(p==0) return 1; long long r = bm(b, p/2); if(p&1) return (((r*r) % MOD) * b) % MOD; return (r*r) % MOD; } struct segment { int l, r; }; bool cmp(segment a, segment b) { return a.l < b.l; } vector<int> adj[MAXN]; char c[MAXN]; bool vis[MAXN]; void dfs(int node, char cur) { c[node] = cur, vis[node] = 1; for(int x: adj[node]) { if(!vis[x]) { dfs(x, (cur == 'A' ? 'B' : 'A')); } } } int st[8 * MAXN]; void u(int l, int r, int tar, int idx, int val) { if(l == r) { st[idx] = val; return; } int mid = (l + r) >> 1; if(tar <= mid) u(l, mid, tar, 2*idx+1, val); else u(mid+1, r, tar, 2*idx+2, val); st[idx] = max(st[2*idx+1], st[2*idx+2]); } int qu(int l, int r, int constl, int constr, int idx) { if(l<=constl && constr<=r) return st[idx]; int mid = (constl+constr) >> 1; if(mid<l || r<constl) return qu(l, r, mid+1, constr, 2*idx+2); else if(constr<l || r<mid+1) return qu(l, r, constl, mid, 2*idx+1); return max(qu(l, r, constl, mid, 2*idx+1), qu(l, r, mid+1, constr, 2*idx+2)); } void update(int i, int v) { u(0, 2*MAXN-1, i, 0, v); } int query(int l, int r) { return qu(l, r, 0, 2*MAXN-1, 0); } void solve(int tc) { int n; cin >> n; segment s[n+1]; for(int i=1; i<=n; i++)cin >> s[i].l >> s[i].r; sort(s+1, s+n+1, cmp); int oops[2*n + 1]; for(int i=1; i<=n; i++) oops[s[i].r] = i; for(int i=1; i<=n; i++) update(s[i].l, s[i].r); for(int i=1; i<=n; i++) { if(s[i].l + 1 == s[i].r) continue; vector<pair<int, int> > v; while(1) { int res = query(s[i].l + 1, s[i].r - 1); if(res > s[i].r) { adj[i].push_back(oops[res]); adj[oops[res]].push_back(i); v.push_back({s[oops[res]].l, res}); update(s[oops[res]].l, -1); } else { break; } } for(pair<int, int> x: v) { update(x.first, x.second); } } int compo = 0; for(int i=1; i<=n; i++) { if(!vis[i]) { compo++; dfs(i, 'A'); } } for(int i=1; i<=n; i++) { for(int x: adj[i]) { if(c[i] == c[x]) { cout << "0\n"; return; } } } cout << bm(2, compo) << '\n'; } int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); int t = 1; //cin >> t; for(int i=1; i<=t; i++) solve(i); } /* 3 3 0 1 1 3 1 2 4 1 0 2 3 1 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...