Submission #674466

#TimeUsernameProblemLanguageResultExecution timeMemory
674466QwertyPiTrampoline (info1cup20_trampoline)C++14
100 / 100
1088 ms52772 KiB
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() #define fi first #define se second using namespace std; map<int, vector<pair<int, int>>> M; pair<int, int> pts[200001]; int nxt[200001], anc[200001][20]; int kth_anc(int u, int k){ for(int j = 19; j >= 0; j--){ if(k >= (1 << j)) u = anc[u][j], k -= (1 << j); } return u; } int main(){ cin.tie(0); cout.tie(0)->sync_with_stdio(false); int r, c, n; cin >> r >> c >> n; for(int i = 0; i < n; i++){ int x, y; cin >> x >> y; M[x].push_back({y, i}); pts[i] = {x, y}; } for(auto& i : M) sort(all(i.second)); for(int i = 0; i < n; i++){ int x = pts[i].fi, y = pts[i].se; if(M.count(x + 1) && lower_bound(all(M[x + 1]), pair<int, int>{y, -1}) != M[x + 1].end()){ pair<int, int> p = *lower_bound(all(M[x + 1]), pair<int, int>{y, -1}); nxt[i] = p.se; }else{ nxt[i] = i; } } for(int j = 0; j < n; j++) anc[j][0] = nxt[j]; for(int i = 1; i < 20; i++){ for(int j = 0; j < n; j++){ anc[j][i] = anc[anc[j][i - 1]][i - 1]; } } int q; cin >> q; for(int i = 0; i < q; i++){ int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2; if(r1 == r2 && c1 <= c2) { cout << "Yes" << endl; continue; } if(c1 > c2 || r1 > r2) { cout << "No" << endl; continue; } if(M.count(r1) && lower_bound(all(M[r1]), pair<int, int>{c1, -1}) != M[r1].end()){ int fr = lower_bound(all(M[r1]), pair<int, int>{c1, -1})->se; int v = kth_anc(fr, r2 - r1 - 1); if(pts[v].fi != r2 - 1 || pts[v].se > c2) { cout << "No" << endl; continue; } cout << "Yes" << endl; }else{ cout << "No" << endl; } } }
#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...