Submission #699910

#TimeUsernameProblemLanguageResultExecution timeMemory
699910KiriLL1caTrampoline (info1cup20_trampoline)C++17
100 / 100
1071 ms81552 KiB
#include <bits/stdc++.h> #define fr first #define sc second #define all(x) (x).begin(), (x).end() #define pb push_back #define endl '\n' #define sz(x) (int)((x).size()) #define vec vector using namespace std; template <typename T> inline bool umin (T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } template <typename T> inline bool umax (T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } typedef long double ld; typedef long long ll; typedef unsigned long long ull; typedef pair <int, int> pii; inline void solve () { int R, C, n; cin >> R >> C >> n; const int lg = 31; vec <pii> gr (n); map <int, vector <int>> mp; for (auto &[x, y] : gr) { cin >> x >> y; mp[x].pb(y); } for (auto &[_, y] : mp) sort(all(y)); sort(all(gr)); vec <vec <int>> up (n, vec <int> (lg)); /// up[i][j] = p /// x[p] = x[i] + 2^j /// y[p] > y[i], y[p] -> min map <pii, int> cp; for (int i = 0; i < n; ++i) { auto [x, y] = gr[i]; cp[gr[i]] = i; auto it = lower_bound(all(gr), make_pair(x + 1, y)); if (it == gr.end() || it->fr != x + 1) up[i][0] = -1; else up[i][0] = (it - gr.begin()); } for (int i = 1; i < lg; ++i) { for (int j = 0; j < n; ++j) { if (!~up[j][i - 1]) up[j][i] = -1; else up[j][i] = up[up[j][i - 1]][i - 1]; } } auto yes = [&] () { cout << "Yes" << endl; }; auto no = [&] () { cout << "No" << endl; }; int q; cin >> q; while (q--) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; if (x1 == x2) { if (y1 <= y2) yes(); else no(); continue; } if (x1 > x2) { no(); continue; } if (!sz(mp[x1])) { no(); continue; } auto it = lower_bound(all(mp[x1]), y1); if (it == mp[x1].end()) { no(); continue; } int go = cp[{x1, *it}], D = x2 - x1 - 1; for (int p = lg - 1; ~p && ~go; --p) { if (D >> p & 1) go = up[go][p]; } if (~go && gr[go].fr + 1 == x2 && gr[go].sc <= y2) yes(); else no(); } } signed main () { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif// LOCAL int t = 1; //cin >> t; while (t--) solve(); return 0; }
#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...