Language: C++

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=100010;
int n,x[maxn],l,q,a,b,vis[maxn],next[maxn][20];
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')
			f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
int query(int s,int e)
{
	int ans=0;
	while(s<e)
	{
		for(int i=19;i>=0;i--)
		if(next[s][i]<=e&&next[s][i])
		{
			s=next[s][i];
			ans+=(1<<i);
			break;
		}
	}
	return ans;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		x[i]=read();
	l=read();
	for(int i=1;i<=n;i++)
		next[i][0]=upper_bound(x+1+1,x+n+1,x[i]+l)-x-1;
	for(int i=1;i<=19;i++)
		for(int j=1;(long long)l*(1<<i)+x[j]<=x[n];j++)
			next[j][i]=next[next[j][i-1]][i-1];
	q=read();
	while(q--)
	{
		a=read(),b=read();
		if(a>b)
			swap(a,b);
		printf("%d\n",query(a,b));
	}
	return 0;
}

Compiler output:
a.cc: In function 'int query(int, int)':
a.cc:33:20: error: reference to 'next' is ambiguous
   33 |                 if(next[s][i]<=e&&next[s][i])
      |                    ^~~~
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:9:33: note:                 'int next [100010][20]'
    9 | int n,x[maxn],l,q,a,b,vis[maxn],next[maxn][20];
      |                                 ^~~~
a.cc:33:35: error: reference to 'next' is ambiguous
   33 |                 if(next[s][i]<=e&&next[s][i])
      |                                   ^~~~
/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:9:33: note:                 'int next [100010][20]'
    9 | int n,x[maxn],l,q,a,b,vis[maxn],next[maxn][20];
      |                                 ^~~~
a.cc:35:27: error: reference to 'next' is ambiguous
   35 |                         s=next[s][i];
      |                           ^~~~
/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:9:33: note:                 'int next [100010][20]'
    9 | int n,x[maxn],l,q,a,b,vis[maxn],next[maxn][20];
      |                                 ^~~~
a.cc: In function 'int main()':
a.cc:49:17: error: reference to 'next' is ambiguous
   49 |                 next[i][0]=upper_bound(x+1+1,x+n+1,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:9:33: note:                 'int next [100010][20]'
    9 | int n,x[maxn],l,q,a,b,vis[maxn],next[maxn][20];
      |                                 ^~~~
a.cc:52:25: error: reference to 'next' is ambiguous
   52 |                         next[j][i]=next[next[j][i-1]][i-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:9:33: note:                 'int next [100010][20]'
    9 | int n,x[maxn],l,q,a,b,vis[maxn],next[maxn][20];
      |                                 ^~~~
a.cc:52:36: error: reference to 'next' is ambiguous
   52 |                         next[j][i]=next[next[j][i-1]][i-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:9:33: note:                 'int next [100010][20]'
    9 | int n,x[maxn],l,q,a,b,vis[maxn],next[maxn][20];
      |                                 ^~~~
a.cc:52:41: error: reference to 'next' is ambiguous
   52 |                         next[j][i]=next[next[j][i-1]][i-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:9:33: note:                 'int next [100010][20]'
    9 | int n,x[maxn],l,q,a,b,vis[maxn],next[maxn][20];
      |                                 ^~~~