Submission #1107679

#TimeUsernameProblemLanguageResultExecution timeMemory
1107679_callmelucianTrampoline (info1cup20_trampoline)C++14
100 / 100
298 ms42436 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> pl; typedef pair<int,int> pii; typedef tuple<int,int,int> tt; #define all(a) a.begin(), a.end() #define filter(a) a.erase(unique(all(a)), a.end()) const int mn = 2e5 + 5; vector<int> cmp, row[mn]; int nxt[mn][21], x[mn], y[mn]; bool found (int targ) { auto it = lower_bound(all(cmp), targ); return it != cmp.end() && *it == targ; } int getID (int targ) { return lower_bound(all(cmp), targ) - cmp.begin() + 1; } int main() { ios::sync_with_stdio(0); cin.tie(0); int r, c, n; cin >> r >> c >> n; for (int i = 1; i <= n; i++) { cin >> x[i] >> y[i]; cmp.push_back(x[i]); } sort(all(cmp)), filter(cmp); for (int i = 1; i <= n; i++) row[getID(x[i])].push_back(i); for (int i = 1; i <= n; i++) sort(all(row[i]), [&] (int a, int b) { return y[a] < y[b]; }); for (int i = 1; i <= n; i++) { if (!found(x[i] + 1)) continue; int cur = getID(x[i] + 1); auto it = lower_bound(all(row[cur]), y[i], [&] (int a, int b) { return y[a] < b; }); if (it != row[cur].end()) nxt[i][0] = *it; } for (int s = 1; s < 21; s++) for (int i = 1; i <= n; i++) nxt[i][s] = nxt[nxt[i][s - 1]][s - 1]; int q; cin >> q; while (q--) { int stx, sty, enx, eny; cin >> stx >> sty >> enx >> eny; if (stx > enx) { cout << "No\n"; continue; } else if (stx == enx) { cout << (sty <= eny ? "Yes" : "No") << "\n"; continue; } else { int curRow = getID(stx); auto it = lower_bound(all(row[curRow]), sty, [&] (int a, int b) { return y[a] < b; }); if (it == row[curRow].end()) { cout << "No\n"; continue; } int cur = *it; for (int step = enx - stx - 1, i = 0; step; step >>= 1, i++) if (step & 1) cur = nxt[cur][i]; cout << (cur && y[cur] <= eny ? "Yes" : "No") << "\n"; } } 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...