Submission #955899

#TimeUsernameProblemLanguageResultExecution timeMemory
955899DAleksaCurtains (NOI23_curtains)C++17
100 / 100
926 ms69812 KiB
#include <bits/stdc++.h> using namespace std; struct query { int l, r; bool ans; }; const int N = 5e5 + 10, inf = 1e9; int n, m, q; vector<int> segments[N]; query all[N]; vector<int> qs[N]; int st[4 * N]; int lzy[4 * N]; void propagate(int index) { if(2 * index + 1 < 4 * N && lzy[index] != 0) { st[2 * index] = max(st[2 * index], lzy[index]); lzy[2 * index] = max(lzy[2 * index], lzy[index]); st[2 * index + 1] = max(st[2 * index + 1], lzy[index]); lzy[2 * index + 1] = max(lzy[2 * index + 1], lzy[index]); lzy[index] = 0; } } void update(int index, int l, int r, int L, int R, int val) { if(l > r || r < L || R < l) return; if(L <= l && r <= R) { st[index] = max(st[index], val); lzy[index] = max(lzy[index], val); return; } propagate(index); int mid = (l + r) / 2; update(2 * index, l, mid, L, R, val); update(2 * index + 1, mid + 1, r, L, R, val); st[index] = min(st[2 * index], st[2 * index + 1]); } int get(int index, int l, int r, int L, int R) { if(l > r || r < L || R < l) return inf; if(L <= l && r <= R) return st[index]; propagate(index); int mid = (l + r) / 2; return min(get(2 * index, l, mid, L, R), get(2 * index + 1, mid + 1, r, L, R)); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); for(int i = 0; i < 4 * N; i++) st[i] = 0; cin >> n >> m >> q; for(int i = 0; i < m; i++) { int l, r; cin >> l >> r; segments[r].push_back(l); } for(int i = 0; i < q; i++) { cin >> all[i].l >> all[i].r; qs[all[i].r].push_back(i); } for(int r = 1; r <= n; r++) { for(int l : segments[r]) update(1, 1, n, l, r, l); for(int ind : qs[r]) { int l = all[ind].l; // cout << l << " " << r << ": " << get(1, 1, n, l, r) << "\n"; if(get(1, 1, n, l, r) == l) all[ind].ans = true; else all[ind].ans = false; } } for(int i = 0; i < q; i++) { if(all[i].ans) cout << "YES\n"; else cout << "NO\n"; } 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...