Submission #680071

#TimeUsernameProblemLanguageResultExecution timeMemory
680071LucaLucaMTrampoline (info1cup20_trampoline)C++17
11 / 100
516 ms29124 KiB
#include <bits/stdc++.h> using namespace std; map<int, vector<int>>lin; #define YES cout << "Yes\n" #define NO cout << "No\n" int n; int nxt[200005][19]; /// nxt[i] - urmatoarea trambulina dupa a[i] struct trambulina { int x, y; bool operator < (const trambulina aux) const { if (x == aux.x) return y < aux.y; return x < aux.x; } }; trambulina a[200005]; int after_jump (int x, int y) { int l=1, r=n; int sol = n + 1; while (l <= r) { int mid = (l + r) / 2; if (a[mid].x < x) l = mid + 1 ; else if (a[mid].x > x) r = mid - 1; else { if (a[mid].y >= y) sol = mid, r = mid-1; else l = mid + 1; } } return sol; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int r, c; cin >> r >> c >> n; for (int i=1; i<=n; i++) cin >> a[i].x >> a[i].y; sort(a+1, a+n+1); a[++n] = {r+1, c+1}; /** nxt[i] - urmatoarea trambulina **/ for (int i=1; i<n; i++) { nxt[i][0] = i; /// coboram cu 2^0 = 1 nivele } for (int j=1; (1 << j) < n; j++) { for (int i=1; i<n; i++) { int pos = nxt[i][j-1]; /// coboram cu 2^(j-1) + 2^(j-1) = 2^j nivele pos = after_jump(a[pos].x+1, a[pos].y); if (pos < n) { pos = nxt[pos][j-1]; nxt[i][j] = pos; } else { nxt[i][j] = n; } } } int t; cin >> t; while (t--) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; if (x1 > x2 || y1 > y2) { NO; continue; } else { int d = x2 - x1; if (d == 0) { YES; continue; } int pos = after_jump(x1, y1); for (int b=0; b<18; b++) { if (d & (1 << b)) { pos = nxt[pos][b]; } } if (pos >= n) { NO; continue; } if (a[pos].x + 1 == x2 && a[pos].y <= y2) YES; else NO; } } 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...