Language: C++

#include <iostream>
#include <utility>
#include <algorithm>
#define inf 1000000007

using namespace std;

int N, L, Q;
int x[100005];
int next[17][100005];

int main(void)
{
	cin >> N;
	for(int i = 0; i < N; i++) cin >> x[i];
	x[N] = x[N-1]+1;
	cin >> L;
	
	int p;
	for(int i = 0; i <= N; i++){
		next[0][i] = upper_bound(x, x+N+1, x[i] + L) - x - 1;
	}
	for(int i = 1; i < 17; i++){
		for(int j = 0; j <= N; j++){
			next[i][j] = next[i-1][next[i-1][j]];
		}
	}
	
	cin >> Q;
	int a, b;
	for(int q = 0; q < Q; q++){
		cin >> a >> b;
		a--, b--;
		if(a > b){
			int t = a;
			a = b, b = t;
		}
		
		int cur = a, ans = 0;
		for(int i = 16; i >= 0; i--){
			if(x[next[i][cur]] <= x[b]){
				cur = next[i][cur];
				ans += 1<<i;
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:21:17: error: reference to 'next' is ambiguous
   21 |                 next[0][i] = upper_bound(x, x+N+1, x[i] + L) - x - 1;
      |                 ^~~~
In file included from /usr/include/c++/14/string:47,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 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:10:5: note:                 'int next [17][100005]'
   10 | int next[17][100005];
      |     ^~~~
a.cc:25:25: error: reference to 'next' is ambiguous
   25 |                         next[i][j] = next[i-1][next[i-1][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:10:5: note:                 'int next [17][100005]'
   10 | int next[17][100005];
      |     ^~~~
a.cc:25:38: error: reference to 'next' is ambiguous
   25 |                         next[i][j] = next[i-1][next[i-1][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:10:5: note:                 'int next [17][100005]'
   10 | int next[17][100005];
      |     ^~~~
a.cc:25:48: error: reference to 'next' is ambiguous
   25 |                         next[i][j] = next[i-1][next[i-1][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:10:5: note:                 'int next [17][100005]'
   10 | int next[17][100005];
      |     ^~~~
a.cc:41:30: error: reference to 'next' is ambiguous
   41 |                         if(x[next[i][cur]] <= x[b]){
      |                              ^~~~
/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:10:5: note:                 'int next [17][100005]'
   10 | int next[17][100005];
      |     ^~~~
a.cc:42:39: error: reference to 'next' is ambiguous
   42 |                                 cur = next[i][cur];
      |                                       ^~~~
/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:10:5: note:                 'int next [17][100005]'
   10 | int next[17][100005];
      |     ^~~~