Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,itit )  for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define mp make_pair
#define pb push_back
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define present(c,x) ((c).find(x) != (c).end())
const double EPS = 1e-8;
const int mod = 1e9+7;
const int N = 5e5+10;
const ll INF = 1e18;

ll power(ll x,ll y){
	ll t=1;
	while(y>0){
		if(y%2) y-=1,t=t*x%mod;
		else y/=2,x=x*x%mod;
	}
return t;
}

char s[N];
int next[N][27];
int ans[N][19];

void make(){
	FILL(next,-1);
	FILL(ans,-1);
	int n=strlen(s),x;
	for(int i=n-1;i>=0;i--){
		x=s[i]-'a';
		next[i][x]=i+1;
		REPP(c,x+1,27)
			if (next[i][c-1]!=-1) next[i][c]=next[next[i][c-1]][c-1];
		if (next[i][26]!=-1){
			REP(c,x) next[i][c]=next[next[i][26]][c];
			ans[i][0]=next[i][26];
			REPP(lvl,1,19) if (ans[i][lvl-1]!=-1) ans[i][lvl]=ans[ans[i][lvl-1]][lvl-1];
		}
	}
}

bool find(int l, int r){
	for(int i=18;i>=0;i--)
		if (ans[l][i]!=-1&&ans[l][i]<=r+1) l=ans[l][i];
	return l==r+1;
}

int main(){
	scanf("%s",s);
	make();
	int q,l,r;
	scanf("%d",&q);
	REP(i,q){
		scanf("%d%d",&l,&r);
		l--,r--;
		if (find(l,r)) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

Compiler output:
a.cc: In function 'void make()':
a.cc:37:14: error: reference to 'next' is ambiguous
   37 |         FILL(next,-1);
      |              ^~~~
a.cc:11:26: note: in definition of macro 'FILL'
   11 | #define FILL(a,x) memset(a,x,sizeof(a))
      |                          ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 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_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:33:5: note:                 'int next [500010][27]'
   33 | int next[N][27];
      |     ^~~~
a.cc:37:14: error: reference to 'next' is ambiguous
   37 |         FILL(next,-1);
      |              ^~~~
a.cc:11:37: note: in definition of macro 'FILL'
   11 | #define FILL(a,x) memset(a,x,sizeof(a))
      |                                     ^
/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:33:5: note:                 'int next [500010][27]'
   33 | int next[N][27];
      |     ^~~~
a.cc:42:17: error: reference to 'next' is ambiguous
   42 |                 next[i][x]=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:33:5: note:                 'int next [500010][27]'
   33 | int next[N][27];
      |     ^~~~
a.cc:44:29: error: reference to 'next' is ambiguous
   44 |                         if (next[i][c-1]!=-1) next[i][c]=next[next[i][c-1]][c-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:33:5: note:                 'int next [500010][27]'
   33 | int next[N][27];
      |     ^~~~
a.cc:44:47: error: reference to 'next' is ambiguous
   44 |                         if (next[i][c-1]!=-1) next[i][c]=next[next[i][c-1]][c-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:33:5: note:                 'int next [500010][27]'
   33 | int next[N][27];
      |     ^~~~
a.cc:44:58: error: reference to 'next' is ambiguous
   44 |                         if (next[i][c-1]!=-1) next[i][c]=next[next[i][c-1]][c-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:33:5: note:                 'int next [500010][27]'
   33 | int next[N][27];
      |     ^~~~
a.cc:44:63: error: reference to 'next' is ambiguous
   44 |                         if (next[i][c-1]!=-1) next[i][c]=next[next[i][c-1]][c-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:33:5: note:                 'int next [500010][27]'
   33 | int next[N][27];
      |     ^~~~
a.cc:45:21: error: reference to 'next' is ambiguous
   45 |                 if (next[i][26]!=-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:33:5: note:                 'int next [500010][27]'
   33 | int next[N][27];
      |     ^~~~
a.cc:46:34: error: reference to 'next' is ambiguous
   46 |                         REP(c,x) next[i][c]=next[next[i][26]][c];
      |                                  ^~~~
/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:33:5: note:                 'int next [500010][27]'
   33 | int next[N][27];
      |     ^~~~
a.cc:46:45: error: reference to 'next' is ambiguous
   46 |                         REP(c,x) next[i][c]=next[next[i][26]][c];
      |                                             ^~~~
/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:33:5: note:                 'int next [500010][27]'
   33 | int next[N][27];
      |     ^~~~
a.cc:46:50: error: reference to 'next' is ambiguous
   46 |                         REP(c,x) next[i][c]=next[next[i][26]][c];
      |                                                  ^~~~
/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:33:5: note:                 'int next [500010][27]'
   33 | int next[N][27];
      |     ^~~~
a.cc:47:35: error: reference to 'next' is ambiguous
   47 |                         ans[i][0]=next[i][26];
      |                                   ^~~~
/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:33:5: note:                 'int next [500010][27]'
   33 | int next[N][27];
      |     ^~~~