Submission #698571

#TimeUsernameProblemLanguageResultExecution timeMemory
698571hazzleTrampoline (info1cup20_trampoline)C++17
42 / 100
1130 ms1048576 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define fi first #define se second #define all(m) (m).begin(), (m).end() #define rall(m) (m).rbegin(), (m).rend() #define vec vector #define sz(a) (int) (a).size() #define mpp make_pair #define mtt make_tuple typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair <int, int> pii; typedef tuple <int, int, int> tui; template <typename T> bool umin(T &a, T b) { return a > b ? a = b, 1 : 0; } template <typename T> bool umax(T &a, T b) { return a < b ? a = b, 1 : 0; } const int N = 2e5 + 42; int solve(){ int r, c, n; cin >> r >> c >> n; vec <pii> a(n); map <pii, int> id; map <int, vec <int>> v; for (int i = 0; i < n; ++i){ auto &[x, y] = a[i]; cin >> x >> y; id[{x, y}] = i; v[x].push_back(y); } for (auto &[x, c]: v) sort(all(c)); auto nxt = [&](int x, int y){ if (v[x].empty()) return -1; auto it = lower_bound(all(v[x]), y); return it == v[x].end() ? -1 : id[mpp(x, *it)]; }; auto prv = [&](int x, int y){ if (v[x].empty()) return -1; auto it = upper_bound(all(v[x]), y); return it == v[x].begin() ? -1 : id[mpp(x, *--it)]; }; vec <vec <int>> g(n); for (int i = 0; i < n; ++i){ auto [x, y] = a[i]; if (~nxt(x, y + 1)){ g[i].push_back(nxt(x, y + 1)); } if (~nxt(x + 1, y)){ g[i].push_back(nxt(x + 1, y)); } } vec <bitset <N>> bb(n); auto dfs = [&](auto &&dfs, int u) -> void { bb[u][u] = 1; for (auto &v: g[u]){ if (!bb[v][v]) dfs(dfs, v); bb[u] |= bb[v]; } }; for (int i = 0; i < n; ++i){ dfs(dfs, i); } // for (int i = 0; i < n; ++i){ // for (auto &j: g[i]){ // auto [cx, cy] = a[i]; // auto [nx, ny] = a[j]; // cout << cx << " " << cy << " -> " << nx << " " << ny << "\n"; // } // } int q; cin >> q; while(q--){ int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty; if (tx < sx || ty < sy){ cout << "No\n"; continue; } if (sx == tx){ cout << "Yes\n"; continue; } int i = nxt(sx, sy); int j = prv(tx, ty); // cout << " try " << i + 1 << " " << j + 1 << "\n"; if (~i && ~j && bb[i][j]){ cout << "Yes\n"; continue; } j = prv(tx - 1, ty); // cout << " try " << i + 1 << " " << j + 1 << "\n"; if (~i && ~j && bb[i][j]){ // cout << i + 1 << " " << j + 1 << " "; cout << "Yes\n"; continue; } cout << "No\n"; } return 0; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tst = 1; //cin >> tst; while(tst--) 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...