Submission #442734

#TimeUsernameProblemLanguageResultExecution timeMemory
442734JovanBTrampoline (info1cup20_trampoline)C++17
100 / 100
972 ms50192 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; map <int, int> comp; const int MAXN = 200000; vector <pair <int, int>> vec[MAXN+5]; int rev[MAXN+5]; const int MXLOG = 18; int jmp[MAXN+5][MXLOG+1]; const int INF = 1000000007; int pi[MAXN+5]; int pj[MAXN+5]; int main(){ ios_base::sync_with_stdio(false), cin.tie(0); cout.precision(10); cout << fixed; int R, C; cin >> R >> C; int n; cin >> n; int tjm = 0; for(int i=1; i<=n; i++){ cin >> pi[i] >> pj[i]; if(!comp[pi[i]]){ comp[pi[i]] = ++tjm; rev[tjm] = pi[i]; } vec[comp[pi[i]]].push_back({pj[i], i}); } pi[n+1] = INF; pj[n+1] = INF; jmp[n+1][0] = n+1; for(int i=1; i<=tjm; i++) sort(vec[i].begin(), vec[i].end()); for(int i=1; i<=tjm; i++){ int sled = comp[rev[i] + 1]; for(auto c : vec[i]) jmp[c.second][0] = n+1; if(sled == 0) continue; for(auto v : vec[i]){ auto p = lower_bound(vec[sled].begin(), vec[sled].end(), make_pair(v.first, 0)); if(p != vec[sled].end()) jmp[v.second][0] = p->second; } } for(int j=1; j<=MXLOG; j++){ for(int i=1; i<=n+1; i++){ jmp[i][j] = jmp[jmp[i][j-1]][j-1]; } } int qrs; cin >> qrs; while(qrs--){ int si, sj, ti, tj; cin >> si >> sj >> ti >> tj; if(si == ti){ cout << (sj <= tj ? "Yes" : "No") << "\n"; continue; } int g = comp[si]; if(!g){ cout << "No\n"; continue; } auto p = lower_bound(vec[g].begin(), vec[g].end(), make_pair(sj, 0)); if(p == vec[g].end()){ cout << "No\n"; continue; } int poc = p->second; for(int j=MXLOG; j>=0; j--){ if(pi[jmp[poc][j]] < ti) poc = jmp[poc][j]; } cout << (pj[poc] <= tj && pi[poc] == ti-1 ? "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...