제출 #1127912

#제출 시각아이디문제언어결과실행 시간메모리
1127912pemguimnCurtains (NOI23_curtains)C++17
100 / 100
929 ms108204 KiB
#include <bits/stdc++.h> #define pii pair<int, int> using namespace std; const int N = 1e6 + 5; struct node{ int x, lz; node(){ x = lz = -1; } }; node unite(const node &x, const node &y){ node ans; ans.x = min(x.x, y.x); return ans; } struct SegmentTree{ vector<node> seg; int n; void init(int _n){ n = _n; seg.resize(4 * n + 5); } void apply(int id, int x){ seg[id].x = max(seg[id].x, x); seg[id].lz = max(seg[id].lz, x); } void down(int id){ int &t = seg[id].lz; apply(id * 2, t), apply(id * 2 + 1, t); t = -1; } void upd(int id, int tl, int tr, int l, int r, int x){ if(r < tl || tr < l) return; if(l <= tl && tr <= r){ apply(id, x); return; } int mid = (tl + tr) / 2; down(id); upd(id * 2, tl, mid, l, r, x), upd(id * 2 + 1, mid + 1, tr, l, r, x); seg[id] = unite(seg[id * 2], seg[id * 2 + 1]); } int query(int id, int tl, int tr, int l, int r){ if(r < tl || tr < l) return N; if(l <= tl && tr <= r) return seg[id].x; int mid = (tl + tr) / 2; down(id); return min(query(id * 2, tl, mid, l, r), query(id * 2 + 1, mid + 1, tr, l, r)); } }; int n, m, q, l[N], r[N], s[N], e[N]; bool ans[N]; vector<int> upd[N]; vector<pii> qq[N]; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); // #define task "noicurtains" // if(fopen(task".inp", "r")){ // freopen(task".inp", "r", stdin); // freopen(task".out", "w", stdout); // } cin >> n >> m >> q; for(int i = 1; i <= m; i++){ cin >> l[i] >> r[i]; upd[r[i]].push_back(l[i]); } for(int i = 1; i <= q; i++){ cin >> s[i] >> e[i]; qq[e[i]].push_back({s[i], i}); } SegmentTree a; a.init(n + 1); for(int i = 1; i <= n; i++){ for(int x : upd[i]) a.upd(1, 1, n, x, i, x); for(pii qu : qq[i]){ if(a.query(1, 1, n, qu.first, i) == qu.first) ans[qu.second] = 1; } } for(int i = 1; i <= q; i++) cout << (ans[i] ? "YES" : "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...