Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 100000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N,Q;
int x[100100];
int next[18][100100];
int L;
int solve(int a,int b){
	if(a>b)swap(a,b);
	int res = 0;
	for(int i=17;i>=0;i--){
		if(next[i][a]<=b){
			res |= (1<<i);
			a = next[i][a];
		}
		if(a==b)break;
	}
	return res;
}
int main(){
	cin >> N;
	for(int i=0;i<N;i++)cin >> x[i];
	cin >> L;
	for(int i=0;i<N;i++){
		next[0][i]=upper_bound(x,x+N,x[i]+L)-x-1;
	}
	for(int i=0;i<17;i++){
		for(int j=0;j<N;j++){
			next[i+1][j]=next[i][next[i][j]];
		}
	}
	cin >> Q;
	for(int i=0;i<Q;i++){
		int a,b;
		cin >> a >> b;
		a--;b--;
		cout << solve(a,b) << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int solve(int, int)':
a.cc:29:20: error: reference to 'next' is ambiguous
   29 |                 if(next[i][a]<=b){
      |                    ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 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_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:23:5: note:                 'int next [18][100100]'
   23 | int next[18][100100];
      |     ^~~~
a.cc:31:29: error: reference to 'next' is ambiguous
   31 |                         a = next[i][a];
      |                             ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:23:5: note:                 'int next [18][100100]'
   23 | int next[18][100100];
      |     ^~~~
a.cc: In function 'int main()':
a.cc:42:17: error: reference to 'next' is ambiguous
   42 |                 next[0][i]=upper_bound(x,x+N,x[i]+L)-x-1;
      |                 ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:23:5: note:                 'int next [18][100100]'
   23 | int next[18][100100];
      |     ^~~~
a.cc:46:25: error: reference to 'next' is ambiguous
   46 |                         next[i+1][j]=next[i][next[i][j]];
      |                         ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:23:5: note:                 'int next [18][100100]'
   23 | int next[18][100100];
      |     ^~~~
a.cc:46:38: error: reference to 'next' is ambiguous
   46 |                         next[i+1][j]=next[i][next[i][j]];
      |                                      ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:23:5: note:                 'int next [18][100100]'
   23 | int next[18][100100];
      |     ^~~~
a.cc:46:46: error: reference to 'next' is ambiguous
   46 |                         next[i+1][j]=next[i][next[i][j]];
      |                                              ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:23:5: note:                 'int next [18][100100]'
   23 | int next[18][100100];
      |     ^~~~