Language: C++

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=100005,BLK=320;

struct Query
{
	int l,r,id;
	bool operator < (const Query &t)const
	{
		if(l/BLK==t.l/BLK)
			return r<t.r;
		return l<t.l;
	}
};

int N,L,Q;
int x[MAXN],left[MAXN],right[MAXN];
Query q[MAXN];
int ans[MAXN];
int dis[MAXN];

int main()
{
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
		scanf("%d",&x[i]);
	scanf("%d%d",&L,&Q);
	for(int i=1;i<=N;i++)
		left[i]=max(lower_bound(x+1,x+N+1,x[i]-L)-x,1);
	for(int i=1;i<=N;i++)
	{
		right[i]=lower_bound(x+1,x+N+1,x[i]+L)-x;
		if(x[right[i]]>x[i]+L)
			right[i]--;
	}
	for(int i=2;i<=N;i++)
		dis[i]=dis[left[i]]+1;
	for(int i=1;i<=Q;i++)
	{
		scanf("%d%d",&q[i].l,&q[i].r);
		if(q[i].l>q[i].r)
			swap(q[i].l,q[i].r);
		printf("%d\n",dis[q[i].r]-dis[q[i].l-1]);
		q[i].id=i;
	}
	sort(q+1,q+Q+1);
	
	/*int L=1,R=1,lm=1,rm=1,ti=0;
	for(int i=1;i<=Q;i++)
	{
		if(L>q[i].l)
		{
			while(lm>q[i].l)
				lm=left[lm],ti++;
			L=q[i].l;
		}
		if(R<q[i].r)
		{
			while(rm<q[i].r)
				rm=right[rm],ti++;
			R=q[i].r;
		}
		if(L<q[i].l)
		{
			while(lm<q[i].l)
				lm=min(right[lm],q[i].l),ti--;
			L=q[i].l;
		}
		if(R>q[i].r)
		{
			while(rm>q[i].r)
				rm=max(left[rm],q[i].r),ti--;
			R=q[i].r;
		}
		ans[q[i].id]=ti;
	}
	for(int i=1;i<=Q;i++)
		printf("%d\n",ans[i]);*/

	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:31:28: error: no matching function for call to 'max(long int, int)'
   31 |                 left[i]=max(lower_bound(x+1,x+N+1,x[i]-L)-x,1);
      |                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:31:28: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
   31 |                 left[i]=max(lower_bound(x+1,x+N+1,x[i]-L)-x,1);
      |                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:31:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   31 |                 left[i]=max(lower_bound(x+1,x+N+1,x[i]-L)-x,1);
      |                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~