Submission #311733

#TimeUsernameProblemLanguageResultExecution timeMemory
311733grtTrampoline (info1cup20_trampoline)C++17
0 / 100
922 ms40408 KiB
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using ll = long long; using pi = pair<int,int>; #define ST first #define ND second #define PB push_back const int nax = 200 * 1000 + 10; int r, c, t, n, nr; map<int, int>sc; vi T[nax]; pi p[nax]; int nxt[nax][19]; bool cmp(int a, int b) { return p[a].ND < p[b].ND; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> r >> c >> n; for(int i = 1; i <= n; ++i) { cin >> p[i].ST >> p[i].ND; sc[p[i].ST]; } for(auto &it : sc) it.ND = ++nr; for(int i = 1; i <= n; ++i) { T[sc[p[i].ST]].PB(i); } for(int i = 1; i <= nr; ++i) { sort(T[i].begin(), T[i].end(), cmp); } for(int i = 1; i <= n; ++i) { if(sc.find(p[i].ST + 1) == sc.end()) { nxt[i][0] = i; } else { int y = sc[p[i].ST + 1]; int low = 0, high = (int)T[y].size() - 1, mid; while(low <= high) { mid = (low + high) / 2; if(p[T[y][mid]].ND >= p[i].ND) { high = mid - 1; } else { low = mid + 1; } } high++; if(high == (int)T[y].size()) { nxt[i][0] = i; } else { nxt[i][0] = T[y][high]; } } } for(int step = 1; step < 19; ++step) { for(int i = 1; i <= n; ++i) { nxt[i][step] = nxt[nxt[i][step - 1]][step - 1]; } } cin >> t; while(t--) { int x, y, a, b; cin >> x >> y >> a >> b; if(x > a || y > b) { cout << "No\n"; continue; } if(x == a) { cout << "Yes\n"; continue; } if(sc.find(x) == sc.end()) { cout << "No\n"; continue; } int start = sc[x]; int low = 0, high = (int)T[start].size() - 1, mid; while(low <= high) { mid = (low + high) / 2; if(p[T[start][mid]].ND >= y) { high = mid - 1; } else { low = high + 1; } } high++; if(high == (int)T[start].size()) { cout << "No\n"; continue; } int w = T[start][high]; for(int step = 18; step >= 0; --step) { if(p[nxt[w][step]].ST <= a) { w = nxt[w][step]; } } if((p[w].ST != a && p[w].ST != (a - 1)) || p[w].ND > b) { cout << "No\n"; continue; } cout << "Yes\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...