Submission #835047

#TimeUsernameProblemLanguageResultExecution timeMemory
835047alex_2008Trampoline (info1cup20_trampoline)C++14
100 / 100
1272 ms81452 KiB
#include <iostream> #include <algorithm> #include <map> #include <vector> #define int long long using namespace std; const int N = 2e5 + 10; map <int, vector<int>> mp; map <pair<int, int>, int> yp; vector <pair<int, int>> v; int a[N]; int dp[N][20]; int ans(int x, int y, int cnt) { int u = yp[{x, y}]; for (int i = 19; i >= 0; i--) { if (cnt & (1 << i)) u = dp[u][i]; if (u == -1) return 1e9 + 10; } return v[u].second; } signed main() { int r, c, n; cin >> r >> c >> n; for (int i = 1; i <= n; i++) { int a, b; cin >> a >> b; mp[a].push_back(b); } for (auto &it : mp) { sort(it.second.begin(), it.second.end()); } int cnt = -1; for (auto it : mp) { for (auto j : it.second) { v.push_back({ it.first, j }); yp[{it.first, j}] = ++cnt; } } for (int i = n - 1; i >= 0; i--) { if (v[i].first == v.back().first) { for (int j = 0; j <= 19; j++) { dp[i][j] = -1; } } else { auto it = mp.find(v[i].first); it++; if (it->first > v[i].first + 1) dp[i][0] = -1; else if (it->second.back() < v[i].second) dp[i][0] = -1; else { int k = lower_bound(it->second.begin(), it->second.end(), v[i].second) - it->second.begin(); dp[i][0] = yp[{v[i].first + 1, it->second[k]}]; } for (int j = 1; j <= 19; j++) { if (dp[i][j - 1] == -1) { dp[i][j] = -1; continue; } dp[i][j] = dp[dp[i][j - 1]][j - 1]; } } } int q; cin >> q; while (q--) { int a, b, c, d; cin >> a >> b >> c >> d; if (a > c || b > d) { cout << "No\n"; continue; } if (a == c) { cout << "Yes\n"; continue; } if (mp.find(a) == mp.end()) { cout << "No\n"; continue; } auto it = mp.find(a); if (it->second.back() < b) { cout << "No\n"; continue; } int j = lower_bound(it->second.begin(), it->second.end(), b) - it->second.begin(); int l = ans(a, it->second[j], c - a - 1); if (l <= d) 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...