Language: C++

#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
//#define __int64 long long
int n,z;
int t[111111];
int next[30][111111];
int q;

int che(int x){

	int l=x+1,r=n-1,mid=(r+l)/2;
	
	while(r-l>1){
		int ab=t[mid]-t[x];
		if(ab>z)r=mid;
		else l=mid;
		mid=(r+l)/2;
	}

	return l;
}

int main(){
	cin>>n;
	rep(i,n)cin>>t[i];
	cin>>z;

	rep(i,n){
		next[0][i]=che(i);
	}

	rep(i,29){
		rep(j,n){
			if(next[i][j]==n)next[i+1][j]=n;
			else next[i+1][j]=next[i][next[i][j]];
		}
	}



	cin>>q;
	rep(i,q){
		int a,b;
		cin>>a>>b;
		if(a>b)swap(a,b);
		a--;b--;
		int ans=0,now=a;	
		for(int j=25;j>=0;j--){
			if(next[j][now]>b)continue;
			ans+=(1<<j);
			now=next[j][now];
		}
		cout<<ans<<endl;
	}
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:43:17: error: reference to 'next' is ambiguous
   43 |                 next[0][i]=che(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:20:5: note:                 'int next [30][111111]'
   20 | int next[30][111111];
      |     ^~~~
a.cc:48:28: error: reference to 'next' is ambiguous
   48 |                         if(next[i][j]==n)next[i+1][j]=n;
      |                            ^~~~
/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:20:5: note:                 'int next [30][111111]'
   20 | int next[30][111111];
      |     ^~~~
a.cc:48:42: error: reference to 'next' is ambiguous
   48 |                         if(next[i][j]==n)next[i+1][j]=n;
      |                                          ^~~~
/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:20:5: note:                 'int next [30][111111]'
   20 | int next[30][111111];
      |     ^~~~
a.cc:49:30: error: reference to 'next' is ambiguous
   49 |                         else 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:20:5: note:                 'int next [30][111111]'
   20 | int next[30][111111];
      |     ^~~~
a.cc:49:43: error: reference to 'next' is ambiguous
   49 |                         else 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:20:5: note:                 'int next [30][111111]'
   20 | int next[30][111111];
      |     ^~~~
a.cc:49:51: error: reference to 'next' is ambiguous
   49 |                         else 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:20:5: note:                 'int next [30][111111]'
   20 | int next[30][111111];
      |     ^~~~
a.cc:63:28: error: reference to 'next' is ambiguous
   63 |                         if(next[j][now]>b)continue;
      |                            ^~~~
/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:20:5: note:                 'int next [30][111111]'
   20 | int next[30][111111];
      |     ^~~~
a.cc:65:29: error: reference to 'next' is ambiguous
   65 |                         now=next[j][now];
      |                             ^~~~
/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:20:5: note:                 'int next [30][111111]'
   20 | int next[30][111111];
      |     ^~~~