Submission #675155

#TimeUsernameProblemLanguageResultExecution timeMemory
675155minhnhatnoeTrampoline (info1cup20_trampoline)C++17
100 / 100
498 ms37908 KiB
#include <bits/stdc++.h>
using namespace std;
int r, c;
const int LG = 20;
vector<pair<int, int>> a;
vector<vector<int>> jmps;
void build_jumps(){
    jmps.assign(a.size(), vector<int> (20));
    for (int i=a.size()-1; i>=0; i--){
        vector<pair<int, int>>::iterator it =
            lower_bound(a.begin(), a.end(), make_pair(a[i].first+1, a[i].second));
        if (it == a.end() || it->first != a[i].first + 1) it = a.end();
        int ptr = it - a.begin();
        jmps[i][0] = ptr;
        for (int p=1; p<LG; p++){
            int dn = jmps[i][p-1];
            if (dn == a.size()) jmps[i][p] = a.size();
            else jmps[i][p] = jmps[dn][p-1];
        }
    }
}
int jump(int ptr, int step){
    if (ptr == a.size()) return a.size();
    if (step > 1000000) return a.size();
    if (step == 0) return ptr;
    int lg2 = 31 - __builtin_clz(step);
    return jump(jmps[ptr][lg2], step - (1<<lg2));
}
bool solve(int xf, int yf, int xt, int yt){
    if (yt < yf || xt < xf)
        return false;
    if (xf == xt)
        return true;
    vector<pair<int, int>>::iterator it =
        lower_bound(a.begin(), a.end(), make_pair(xf, yf));
    if (it == a.end() || it->first != xf)
        return false;
    int ptrstart = it - a.begin();
    int dest = jump(ptrstart, xt - xf - 1);
    if (dest == a.size() || a[dest].second > yt) return false;
    return true;
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    cin >> r >> c;
    int n; cin >> n;
    a.resize(n);
    for (int i=0; i<n; i++)
        cin >> a[i].first >> a[i].second;
    sort(a.begin(), a.end());
    build_jumps();
    int t; cin >> t;
    while (t--){
        int xf, yf, xt, yt; cin >> xf >> yf >> xt >> yt;
        if (solve(xf, yf, xt, yt))
            cout << "Yes\n";
        else
            cout << "No\n";
    }
}

Compilation message (stderr)

trampoline.cpp: In function 'void build_jumps()':
trampoline.cpp:17:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |             if (dn == a.size()) jmps[i][p] = a.size();
      |                 ~~~^~~~~~~~~~~
trampoline.cpp: In function 'int jump(int, int)':
trampoline.cpp:23:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     if (ptr == a.size()) return a.size();
      |         ~~~~^~~~~~~~~~~
trampoline.cpp: In function 'bool solve(int, int, int, int)':
trampoline.cpp:40:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     if (dest == a.size() || a[dest].second > yt) return false;
      |         ~~~~~^~~~~~~~~~~
#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...