Submission #862350

#TimeUsernameProblemLanguageResultExecution timeMemory
862350TAhmed33Osumnjičeni (COCI21_osumnjiceni)C++98
40 / 110
1060 ms254176 KiB
#include <bits/stdc++.h> using namespace std; #define mid ((l + r) >> 1) bool intersect (pair <int, int> a, pair <int, int> b) { return !(a.second < b.first || b.second < a.first); } const int MAXN = 2e5 + 25; const int MAXL = 1e9 + 25; const int MAXN2 = 2e7 + 25; struct SegmentTree { vector <int> tree, lazy, tl, tr; int cnt = 0; void p () { tree.push_back(1e9); lazy.push_back(1e9); tl.push_back(-1); tr.push_back(-1); } void init () { p(); } void ext (int node) { if (tl[node] == -1) { tl[node] = ++cnt; p(); } if (tr[node] == -1) { tr[node] = ++cnt; p(); } } void prop (int l, int r, int node) { if (lazy[node] == -1) return; if (l != r) { ext(node); lazy[tl[node]] = lazy[node]; lazy[tr[node]] = lazy[node]; } tree[node] = lazy[node]; lazy[node] = -1; } void update (int l, int r, int a, int b, int c, int node) { prop(l, r, node); if (l > b || r < a) return; if (l >= a && r <= b) { lazy[node] = c; prop(l, r, node); return; } ext(node); update(l, mid, a, b, c, tl[node]); update(mid + 1, r, a, b, c, tr[node]); tree[node] = min(tree[tl[node]], tree[tr[node]]); } int get (int l, int r, int a, int b, int node) { prop(l, r, node); if (l > b || r < a) return 1e9; if (l >= a && r <= b) return tree[node]; int sum = 1e9; if (tl[node] != -1) sum = get(l, mid, a, b, tl[node]); if (tr[node] != -1) sum = min(sum, get(mid + 1, r, a, b, tr[node])); return sum; } } cur; pair <int, int> arr[MAXN]; int nxt[MAXN]; int main () { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) cin >> arr[i].first >> arr[i].second; cur.init(); cur.update(1, MAXL, 1, MAXL, n + 1, 1); for (int i = n; i >= 1; i--) { nxt[i] = cur.get(1, MAXL, arr[i].first, arr[i].second, 1); if (i < n) nxt[i] = min(nxt[i], nxt[i + 1]); cur.update(1, MAXL, arr[i].first, arr[i].second, i, 1); } int q; cin >> q; while (q--) { int l, r; cin >> l >> r; int dp[n + 2] = {}; for (int i = r; i >= l; i--) { if (nxt[i] > r) { dp[i] = 1; } else { dp[i] = 1 + dp[nxt[i]]; } } cout << dp[l] << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...