Submission #920881

#TimeUsernameProblemLanguageResultExecution timeMemory
920881siewjhTrampoline (info1cup20_trampoline)C++17
100 / 100
758 ms51780 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 200005; int rv[MAXN], cv[MAXN], nxt[MAXN][20]; map<int, vector<pair<int, int>>> m; int xpar(int a, int x){ for (int k = 19; k >= 0; k--){ if (a == -1) break; if (x & (1 << k)) a = nxt[a][k]; } return a; } bool solve(){ int sr, sc, er, ec; cin >> sr >> sc >> er >> ec; if (er < sr || ec < sc) return 0; if (er == sr) return 1; if (!m.count(sr)) return 0; auto it = lower_bound(m[sr].begin(), m[sr].end(), make_pair(sc, -1)); if (it == m[sr].end()) return 0; int finc = xpar(it->second, er - sr - 1); if (finc == -1) return 0; return cv[finc] <= ec; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int rows, cols, nums; cin >> rows >> cols >> nums; for (int i = 0; i < nums; i++){ int r, c; cin >> r >> c; rv[i] = r; cv[i] = c; m[r].push_back({c, i}); } for (auto &[r, v] : m) sort(v.begin(), v.end()); for (int i = 0; i < nums; i++){ int r = rv[i], c = cv[i]; if (!m.count(r + 1)) nxt[i][0] = -1; else{ auto it = lower_bound(m[r + 1].begin(), m[r + 1].end(), make_pair(c, -1)); if (it == m[r + 1].end()) nxt[i][0] = -1; else nxt[i][0] = it->second; } } for (int k = 1; k <= 19; k++) for (int i = 0; i < nums; i++){ if (nxt[i][k - 1] == -1) nxt[i][k] = -1; else nxt[i][k] = nxt[nxt[i][k - 1]][k - 1]; } int queries; cin >> queries; while (queries--) cout << (solve() ? "Yes" : "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...