Language: C++

#include<bits/stdc++.h>

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
typedef struct aaaaa{
  int x,y,t;
}Grid;
using namespace std;
int main(){
  int n;cin>>n;
  vector<ll>ori(n);
  vector<vector<ll> >vvll(n);
  map<ll,int>mli;
  bool used[n+10]={};
  for(int i=0;i<n;i++)
    cin>>ori[i];
  ll L;cin>>L;
  int q;cin>>q;
  ori.pb(llINF);
  int cnt=0;
  for(int i=0;i<n;i++){
    if(used[i])continue;
    vvll[cnt].pb(ori[i]);
    ll hoge=ori[i];
    mli[i]=cnt;
    while(hoge!=llINF){
      auto po = upper_bound(ALL(ori),hoge+L);
      if(*po == llINF){
	if(ori[ori.size()-2]-hoge<=L){
	  mli[ori.size()-2]=cnt;
	  used[ori.size()-2]=true;
	  vvll[cnt].pb(ori[ori.size()-2]);
	  break;
	}
      }
      int num=max((po-ori.begin())-1,0LL);
      used[num]=true;
      hoge = ori[num];
      mli[num]=cnt;
      vvll[cnt].pb(ori[num]);
    }
    cnt++;
  }
  /* for(int i=0;i<vvll.size();i++){
    for(int j=0;j<vvll[i].size();j++)
      cout<<vvll[i][j]<<" ";
    cout<<endl;
    }*/

  for(int i=0;i<q;i++){
    int le,ri;cin>>le>>ri;
    //cout<<mli[min(le,ri)-1]<<endl;
    //cout<<ori[min(le,ri)-1]<<" "<<ori[max(le,ri)-1]<<endl;
    auto a = lower_bound(ALL(vvll[mli[min(le,ri)-1]]),ori[min(le,ri)-1]);
    auto b = lower_bound(ALL(vvll[mli[min(le,ri)-1]]),ori[max(le,ri)-1]);
    cout<<(b-a)<<endl;
  }
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:45:18: error: no matching function for call to 'max(__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type, long long int)'
   45 |       int num=max((po-ori.begin())-1,0LL);
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included 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_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:45:18: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
   45 |       int num=max((po-ori.begin())-1,0LL);
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~
/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:45:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   45 |       int num=max((po-ori.begin())-1,0LL);
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~