Submission #113623

#TimeUsernameProblemLanguageResultExecution timeMemory
113623aminraPort Facility (JOI17_port_facility)C++14
0 / 100
168 ms196188 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const int MOD = (int)1e9 + 7; const int MAXN = (int)2e6 + 3; const int infint = (int)2e9; const ll inf = (ll)2e18; int a[MAXN], b[MAXN], id[MAXN], n, par[MAXN], sz; int get(int u) { return par[u] < 0 ? u : par[u] = get(par[u]); } void merge(int u, int v) { if((u = get(u)) == (v = get(v))) return; sz--; if(par[u] > par[v]) swap(u, v); par[u] += par[v]; par[v] = u; } vector<int> seg[4 * MAXN]; bool odd[4 * MAXN], cyc; bool cmp(int u, int v) { return a[u] < a[v]; } void add(int node, int st, int en, int idx, int val) { if(odd[node]) cyc = 1; if(seg[node].size()) odd[node] = 1; for (auto u : seg[node]) merge(u, val); seg[node].clear(); if(en - st < 2) return; int mid = (st + en) >> 1; if(idx < mid) add(node << 1, st, mid, idx, val); else add(node << 1 | 1, mid, en, idx, val); return; } void ask(int node, int st, int en, int l, int r, int val) { if(l >= en || st >= r) return; if(l <= st && en <= r) { seg[node].push_back(val); return; } int mid = (st + en) >> 1; ask(node << 1, st, mid, l, r, val); ask(node << 1 | 1, mid, en, l, r, val); return; } int pwr(int a, int b) { if(b == 0) return 1; int c = pwr(a, b >> 1); c = 1LL * c * c % MOD; if(b & 1) c = 1LL * c * a % MOD; return c; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; sz = n; for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; memset(par, -1, sizeof par); for (int i = 0; i < n; i++) id[i] = i, a[i]--, b[i]--; sort(id, id + n, cmp); for (int i = n - 1; i >= 0; i--) { add(1, 0, 2 * n, b[id[i]], id[i]); ask(1, 0, 2 * n, a[id[i]], b[id[i]] + 1, id[i]); if(cyc) return cout << 0, 0; } cout << pwr(2, sz); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...