Language: C++

#include<bits/stdc++.h>
using namespace std;
#define N 100000 + 5
#define rep(i, l, r) for(int i = l; i <= r; ++i)
int n, l, q, a, b, tot, size, x[N], nxt[N], last[N], cntb[N], block[N];
int read(){
    char c; int x = 0, f = 1;
    c = getchar();
    while(c > '9' || c < '0'){ if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int main(){
    n = read(), size = sqrt(n), tot = ceil(1.0 * n / size);
    rep(i, 1, n) x[i] = read();
    l = read(); 
    rep(i, 1, n){
        int pos = upper_bound(x + 1, x + n + 1, x[i] + l) - x;
        if(x[pos] < x[i] + l) last[i] = n + 1;
        else last[i] = pos - 1;
    }
    block[n + 1] = tot + 1;
    rep(i, 1, n) block[i] = i / size + 1;
    rep(i, 1, n){
        int pos = i, cnt = 0;
        while(block[pos] == block[i]) pos = last[pos], ++cnt;
        cntb[i] = cnt, nxt[i] = pos;
    }
    q = read();
    while(q--){
        a = read(), b = read(); if(a > b) swap(a, b);
        int pos = a, ans = 0;
        while(block[pos] != block[b]) ans += cntb[pos], pos = nxt[pos];
        while(pos < b) pos = last[pos], ++ans;
        printf("%d\n", ans);
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:14:17: error: reference to 'size' is ambiguous
   14 |     n = read(), size = sqrt(n), tot = ceil(1.0 * n / size);
      |                 ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:5:25: note:                 'int size'
    5 | int n, l, q, a, b, tot, size, x[N], nxt[N], last[N], cntb[N], block[N];
      |                         ^~~~
a.cc:14:54: error: reference to 'size' is ambiguous
   14 |     n = read(), size = sqrt(n), tot = ceil(1.0 * n / size);
      |                                                      ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:5:25: note:                 'int size'
    5 | int n, l, q, a, b, tot, size, x[N], nxt[N], last[N], cntb[N], block[N];
      |                         ^~~~
a.cc:23:33: error: reference to 'size' is ambiguous
   23 |     rep(i, 1, n) block[i] = i / size + 1;
      |                                 ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:5:25: note:                 'int size'
    5 | int n, l, q, a, b, tot, size, x[N], nxt[N], last[N], cntb[N], block[N];
      |                         ^~~~