Submission #675258

#TimeUsernameProblemLanguageResultExecution timeMemory
675258TranGiaHuy1508Trampoline (info1cup20_trampoline)C++17
100 / 100
670 ms41164 KiB
#include <bits/stdc++.h> using namespace std; void main_program(); signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); main_program(); } int R, C, n, q; vector<pair<int, int>> inp; map<int, vector<pair<int, int>>> mp; int nxt[21][200'005]; void main_program(){ cin >> R >> C >> n; inp.resize(n+1); for (int i = 0; i < n; i++){ int a, b; cin >> a >> b; inp[i+1] = {a, b}; mp[a].emplace_back(b, i+1); } for (auto &[key, value]: mp){ sort(value.begin(), value.end()); } for (int i = 0; i <= n; i++) nxt[0][i] = 0; for (auto it = mp.rbegin(); it != mp.rend(); it++){ auto [x, vy] = *it; if (!mp.count(x+1)) continue; for (auto [y, i]: vy){ auto it2 = lower_bound(mp[x+1].begin(), mp[x+1].end(), make_pair(y, -1)); if (it2 == mp[x+1].end()) continue; auto [x2, j] = *it2; // cout << "EDGE " << i << " " << j << "\n"; nxt[0][i] = j; } } for (int lg = 1; lg < 21; lg++){ for (int i = 0; i <= n; i++){ nxt[lg][i] = nxt[lg-1][nxt[lg-1][i]]; } } cin >> q; for (int qr = 0; qr < q; qr++){ int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; if (x1 > x2){ cout << "No\n"; continue; } if (x1 == x2){ if (y1 <= y2) cout << "Yes\n"; else cout << "No\n"; continue; } if (y1 > y2){ cout << "No\n"; continue; } int D = x2 - x1 - 1; int crr = 0; if (mp.count(x1)){ auto it = lower_bound(mp[x1].begin(), mp[x1].end(), make_pair(y1, -1)); if (it != mp[x1].end()){ crr = (*it).second; } } // cout << ":: " << crr << "\n"; for (int lg = 20; lg >= 0; lg--){ if ((D >> lg) & 1) crr = nxt[lg][crr]; } if (!crr) cout << "No\n"; else{ if (inp[crr].second <= y2) cout << "Yes\n"; else cout << "No\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...