Submission #930889

#TimeUsernameProblemLanguageResultExecution timeMemory
930889vjudge1Curtains (NOI23_curtains)C++17
100 / 100
831 ms80328 KiB
#include <iostream> #include <vector> #include <cstring> using namespace std; int t[2000005], tt[2000005], res[500005]; vector<int> g[500005]; vector<pair<int, int>> gg[500005]; void update(int v, int tl, int tr, int l, int r, int x) { if (l > r) return; if (tl == l && r == tr) { t[v] = min(t[v], x); tt[v] = min(tt[v], x); return; } int mid = (tl + tr) / 2; update(v * 2, tl, mid, l, min(r, mid), x); update(v * 2 + 1, mid + 1, tr, max(l, mid + 1), r, x); t[v] = min(max(t[v * 2], t[v * 2 + 1]), tt[v]); } int sum(int v, int tl, int tr, int l, int r) { if (l > r) return 1e9 + 1; if (tl == l && tr == r) { return t[v]; } int mid = (tl + tr) / 2; int h = sum(v * 2, tl, mid, l, min(r, mid)), k = sum(v * 2 + 1, mid + 1, tr, max(l, mid + 1), r); if (h == 1e9 + 1) return min(k, tt[v]); if (k == 1e9 + 1) return min(h, tt[v]); return min(max(h, k), tt[v]); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, q; cin >> n >> m >> q; for (int i = 1; i <= m; i++) { int u, v; cin >> u >> v; g[u].push_back(v); } for (int i = 0; i < q; i++) { int u, v; cin >> u >> v; gg[u].push_back({v, i}); } for (int i = 1; i <= n * 4; i++) t[i] = tt[i] = 1e9; for (int i = n; i >= 1; i--) { for (int w : g[i]) { update(1, 1, n, i, w, w); } for (auto w : gg[i]) { if (sum(1, 1, n, i, w.first) <= w.first) { res[w.second] = 1; } } } for (int i = 0; i < q; i++) { if (res[i] == 0) cout << "NO"; else cout << "YES"; cout << '\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...
#Verdict Execution timeMemoryGrader output
Fetching results...