Submission #690857

#TimeUsernameProblemLanguageResultExecution timeMemory
690857andrei_iorgulescuTrampoline (info1cup20_trampoline)C++14
11 / 100
331 ms31120 KiB
#include <bits/stdc++.h> using namespace std; int r,c,n,t; pair<int,int>a[200005]; int nxt[200005][20]; int lg[200005]; void nxt0() { stack<int>s; for (int i = n; i >= 1; i--) { while (!s.empty() and a[s.top()].second < a[i].second) s.pop(); if (!s.empty()) nxt[i][0] = s.top(); s.push(i); } } void prec() { nxt0(); for (int i = 2; i <= 200000; i++) lg[i] = 1 + lg[i / 2]; for (int j = 1; j <= lg[n]; j++) { for (int i = 1; i <= n - (1 << j) + 1; i++) { int n1 = nxt[i][j - 1]; if (n1 == 0) nxt[i][j] = 0; else { int n2 = nxt[n1][j - 1]; if (n2 == 0) nxt[i][j] = 0; else nxt[i][j] = n2; } } } /*for (int j = 0; j <= lg[n]; j++) { for (int i = 1; i <= n - (1 << j) + 1; i++) cout << nxt[i][j] << ' '; cout << '\n'; }*/ } void jump(int x,int y) { int pas = lg[n]; while (pas != -1) { if (nxt[x][pas] != 0 and nxt[x][pas] <= y) x = nxt[x][pas]; pas--; } if (x == y) cout << "Yes\n"; else cout << "No\n"; } void query(int xs,int ys,int xf,int yf) { if (xs > xf or ys > yf) { cout << "No\n"; return; } if (xs == xf) { cout << "Yes\n"; return; } int ts = 0,tf = 0; int pas = 1 << 17; pair<int,int>cp = {xs,ys}; while (pas != 0) { if (ts + pas <= n and a[ts + pas] < cp) ts += pas; pas /= 2; } ts++; if (ts <= n and a[ts].first == xs) ts += 0; else ts = 0; xf--; pas = 1 << 17; cp = {xf,yf}; while (pas != 0) { if (tf + pas <= n and a[tf + pas] <= cp) tf += pas; pas /= 2; } if (tf != 0 and a[tf].first == xf) tf += 0; else tf = 0; //cout << ts << ' ' << tf << '\n'; if (ts == 0 or tf == 0) { cout << "No\n"; return; } jump(ts,tf); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> r >> c >> n; for (int i =1 ; i <= n; i++) cin >> a[i].first >> a[i].second; sort(a + 1,a + n + 1); prec(); cin >> t; for (int i =1 ; i <= t; i++) { int xs,ys,xf,yf; cin >> xs >> ys >> xf >> yf; query(xs,ys,xf,yf); } 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...