Submission #426909

#TimeUsernameProblemLanguageResultExecution timeMemory
426909pavementTrampoline (info1cup20_trampoline)C++17
100 / 100
1530 ms98352 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; #ifdef _WIN32 #define getchar_unlocked _getchar_nolock #endif #define int long long #define mp make_pair #define mt make_tuple #define pb push_back #define ppb pop_back #define eb emplace_back #define g0(a) get<0>(a) #define g1(a) get<1>(a) #define g2(a) get<2>(a) #define g3(a) get<3>(a) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef double db; typedef long long ll; typedef long double ld; typedef pair<int, int> ii; typedef tuple<int, int, int> iii; typedef tuple<int, int, int, int> iiii; typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; int R, C, N, T, r1, c1, r2, c2, a[200005], b[200005], anc[200005][25]; bool in[200005]; vector<int> adj[200005]; map<ii, int> _lab; map<int, vector<int> > vec; inline int lab(int a, int b) { assert(_lab.find(mp(a, b)) != _lab.end()); return _lab[mp(a, b)]; } void dfs(int n, int e = -1) { anc[n][0] = e; for (int i = 1; i <= 20; i++) if (anc[n][i - 1] != -1) anc[n][i] = anc[anc[n][i - 1]][i - 1]; for (auto u : adj[n]) if (u != e) dfs(u, n); } main() { memset(anc, -1, sizeof anc); ios::sync_with_stdio(0); cin.tie(0); cin >> R >> C >> N; for (int i = 1; i <= N; i++) { cin >> a[i] >> b[i]; vec[a[i]].pb(b[i]); _lab[mp(a[i], b[i])] = i; } for (auto &i : vec) sort(i.second.begin(), i.second.end()); for (auto i : vec) { for (int j : i.second) { auto tmp = lower_bound(vec[i.first + 1].begin(), vec[i.first + 1].end(), j); if (tmp != vec[i.first + 1].end()) { adj[lab(i.first + 1, *tmp)].pb(lab(i.first, j)); in[lab(i.first, j)] = 1; } } } for (int i = 1; i <= N; i++) { if (!in[i]) dfs(i); } cin >> T; while (T--) { cin >> r1 >> c1 >> r2 >> c2; if (r1 > r2) cout << "No\n"; else if (r1 == r2) { if (c1 <= c2) cout << "Yes\n"; else cout << "No\n"; } else { auto tmp = lower_bound(vec[r1].begin(), vec[r1].end(), c1); if (tmp != vec[r1].end()) { int curr = lab(r1, *tmp), up = 0; for (int i = 20; i >= 0; i--) if (anc[curr][i] != -1 && up + (1 << i) < r2 - r1) { curr = anc[curr][i]; up += (1 << i); assert(a[curr] == r1 + up); } if (a[curr] == r2 - 1 && b[curr] <= c2) cout << "Yes\n"; else cout << "No\n"; } else cout << "No\n"; } } }

Compilation message (stderr)

trampoline.cpp:46:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   46 | main() {
      | ^~~~
#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...