Language: C++

#include <bits/stdc++.h>
using namespace std;
using Pint = pair<int, int>;

int N, L, Q;
vector<int> x;
vector<Pint> q;

int main()
{
    cin >> N;
    x.resize(N);
    for (auto &val : x) cin >> val;
    x.push_back(x[N-1]+1);
    cin >> L >> Q;
    q.resize(Q);
    for (int i=0; i<Q; i++)
    {
        int t1, t2;
        cin >> t1 >> t2;
        
        if (t1>t2) swap(t1, t2);
        q[i] = Pint(t1-1, t2-1);
    }
    int lgN = 1;
    {
        int tmp = N;
        while (tmp)
        {
            lgN++;
            tmp /= 2;
        }
    }
    vector<vector<int> > next(lgN+1, vector<int>(N+1));
    for (int i=0; i<=N; i++)
    {
        next[1][i] = min(distance(x.begin(), lower_bound(x.begin(), x.end(), x[i]+L+1)) - 1, N);
    }

    for (int n=2; n<=lgN; n++)
    {
        for (int i=0; i<=N; i++)
        {
            next[n][i] = next[n-1][next[n-1][i]];
        }
    }
    // for (auto vec : next)
    // {
    //     for (auto val : vec) cout << val << " ";
    //     cout << endl;
    // }

    for (auto query : q)
    {
        int ans = 0;
        int now = query.first;
        for (int n = lgN; n>0; n--)
        {
            if (next[n][now] < query.second)
            {
                ans += n;
                now = next[n][now];
            }
        }
        cout << ans + 1 << endl;
    }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:37:25: error: no matching function for call to 'min(std::__iterator_traits<__gnu_cxx::__normal_iterator<int*, std::vector<int> >, void>::difference_type, int&)'
   37 |         next[1][i] = min(distance(x.begin(), lower_bound(x.begin(), x.end(), x[i]+L+1)) - 1, N);
      |                      ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:37:25: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
   37 |         next[1][i] = min(distance(x.begin(), lower_bound(x.begin(), x.end(), x[i]+L+1)) - 1, N);
      |                      ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:37:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   37 |         next[1][i] = min(distance(x.begin(), lower_bound(x.begin(), x.end(), x[i]+L+1)) - 1, N);
      |                      ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~