제출 #1145639

#제출 시각아이디문제언어결과실행 시간메모리
1145639saidponTrampoline (info1cup20_trampoline)C++20
0 / 100
745 ms55424 KiB
#include <bits/stdc++.h> #define nemeshay ios_base::sync_with_stdio(NULL), cin.tie(0), cout.tie(0); #define int long long #define sigma signed #define pb push_back #define fr first #define sc second #define pii pair<int, int> #define double long double #define YES cout << "YES" << endl #define NO cout << "NO" << endl #define Yes cout << "Yes" << endl #define No cout << "No" << endl #define OK cout << "OK" << endl #define Ok cout << "Ok" << endl #define nosolve cout << "-1" << endl using namespace std; const int N = 2e5 + 2, inf = 1e18 + 7, mod = 998244353; pii a[N]; int used[N], anc[N][20]; vector <int> pon[N]; void dfs(int u, int p) { used[u] = 1; anc[u][0] = p; for (int i = 1; i < 20; i++) anc[u][i] = anc[anc[u][i - 1]][i - 1]; for (auto v: pon[u]) if (v != p) dfs(v, u); } sigma main() { int R, C, n; cin >> R >> C >> n; for (int i = 1; i <= n; i++) cin >> a[i].fr >> a[i].sc; sort (a + 1, a + n + 1); for (int i = n; i > 0; i--) { auto check = [&](int ind) { return a[i].fr - a[ind].fr > 1 || (a[i].fr - a[ind].fr == 1 && a[ind].sc <= a[i].sc); }; int l = 1, r = i - 1; while (r - l > 1) { int m = l + r >> 1; if (check(m)) l = m; else r = m; } if (a[i].fr - a[r].fr == 1 && a[r].sc <= a[i].sc) pon[r].pb(i), pon[i].pb(r); else if (a[i].fr - a[l].fr == 1 && a[l].sc <= a[i].sc) pon[l].pb(i), pon[i].pb(l); } for (int i = 1; i <= n; i++) { if (used[i]) continue; dfs(i, 0); } int q; cin >> q; while (q--) { int xs, ys, xf, yf; cin >> xs >> ys >> xf >> yf; if (xs > xf || ys > yf) { No; continue; } if (xs == xf) { Yes; continue; } xf--; auto check = [&](int ind) { return a[ind].fr < xf || (a[ind].fr == xf && a[ind].sc <= yf); }; int l = 1, r = n, ind = 0; while (r - l > 1) { int m = l + r >> 1; if (check(m)) l = m; else r = m; } if (xf == a[r].fr && a[r].sc <= yf) ind = r; else if (xf == a[l].fr && a[l].sc <= yf) ind = l; if (!ind || xf != a[ind].fr) { No; continue; } cout << ind << ' '; for (int i = 0; i < 20; i++) if ((xf - xs) & (1 << i)) ind = anc[ind][i]; cout << ind << ' ' << xf - xs << endl; if (!ind || a[ind].sc < ys) No; else Yes; } } /* 5 5 7 1 1 1 2 2 2 2 3 3 3 4 3 4 4 10 1 1 5 5 */
#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...