Submission #354251

#TimeUsernameProblemLanguageResultExecution timeMemory
354251valerikkTrampoline (info1cup20_trampoline)C++14
100 / 100
824 ms62952 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; const int L = 20; int R, C, n; pair<int, int> green[N]; int a[N], b[N]; int go[L][N]; int main() { #ifdef LOCAL freopen("input.txt", "r", stdin); #endif ios::sync_with_stdio(false); cin.tie(0); cin >> R >> C >> n; for (int i = 0; i < n; ++i) cin >> green[i].second >> green[i].first; green[n] = {C + 1, R + 1}; sort(green, green + n + 1); for (int i = 0; i <= n; ++i) a[i] = green[i].second, b[i] = green[i].first; for (int i = 0; i <= n; ++i) go[0][i] = n; map<int, int> last; for (int i = n - 1; i >= 0; --i) { if (last.find(a[i] + 1) != last.end()) go[0][i] = last[a[i] + 1]; last[a[i]] = i; } for (int p = 1; p < L; ++p) { for (int i = 0; i <= n; ++i) go[p][i] = go[p - 1][go[p - 1][i]]; } map<int, vector<pair<int, int>>> for_x; for (int i = 0; i <= n; ++i) for_x[a[i]].emplace_back(b[i], i); int t; cin >> t; while (t--) { int xstart, ystart, xstop, ystop; cin >> xstart >> ystart >> xstop >> ystop; if (xstart > xstop || ystart > ystop) { cout << "No\n"; } else if (xstart == xstop) { cout << "Yes\n"; } else { auto it = lower_bound(for_x[xstart].begin(), for_x[xstart].end(), make_pair(ystart, 0)); if (it == for_x[xstart].end() || it->first > ystop) { cout << "No\n"; } else { int pos = it->second; for (int i = L - 1; i >= 0; --i) { if (b[go[i][pos]] <= ystop) pos = go[i][pos]; } if (a[pos] + 1 >= xstop) 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...