Submission #244181

#TimeUsernameProblemLanguageResultExecution timeMemory
244181Osama_AlkhodairyPort Facility (JOI17_port_facility)C++17
0 / 100
5 ms384 KiB
#include <bits/stdc++.h> using namespace std; #define finish(x) return cout << x << endl, 0 #define ll long long const int N = 2000001; int n, tree[4 * N], mod = 1e9 + 7; vector <int> a; void update(int l, int r, int node, int idx, int val){ if(r < l || r < idx || l > idx) return; if(l == r){ tree[node] += val; return; } int mid = (l + r) / 2; update(l, mid, 2 * node, idx, val); update(mid + 1, r, 2 * node + 1, idx, val); tree[node] = max(tree[2 * node], tree[2 * node + 1]); } int query(int l, int r, int node, int s, int e){ if(r < l || r < s || l > e) return -1e9; if(s <= l && r <= e) return tree[node]; int mid = (l + r) / 2; return max(query(l, mid, 2 * node, s, e), query(mid + 1, r, 2 * node + 1, s, e)); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; a.resize(2 * n); vector <int> l(n + 1), r(n + 1); for(int i = 1 ; i <= n ; i++){ cin >> l[i] >> r[i]; l[i]--; r[i]--; a[l[i]] = i; a[r[i]] = -i; } int ans = 1; for(auto &i : a){ if(i < 0){ int cur = -i; for(int j = l[cur] ; j < r[cur] ; j++){ if(a[j] > 0 && r[a[j]] > r[cur]){ update(0, 2 * n, 1, r[a[j]], -1); } } continue; } int b = query(0, 2 * n, 1, l[i], r[i]); if(b >= 2) finish(0); else if(b == 0){ ans *= 2; if(ans >= mod) ans -= mod; } update(0, 2 * n, 1, r[i], b + 1); } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...