Language: C++

#include<bits/stdc++.h>
#define idx(x) (x-'a')
using namespace std;
const int maxn=5e5+10;
const int inf=1061109567;
char s[maxn];
int n,q,next[maxn][27];
int main()
{
    int i,j,k;
    scanf("%s%d",s+1,&q);
    memset(next,inf,sizeof(next));
    for(n=0;s[n+1];n++); 
    for(i=1;i<=n;i++)
        next[i][idx(s[i])]=i;
    for(i=n;i;i--){
        for(k=1;k<27;k++){
            if(next[i][k-1]<inf){
                j=next[i][k-1];
                j=next[j+1][k-1];
                if(j<inf)
                    next[i][k]=min(next[i][k],j);
            }
        }
        if(next[i][26]<inf){
            for(k=1;k<27;k++){
                j=next[i][26];
                j=next[j+1][k];
                if(j<inf)
                    next[i][k]=min(next[i][k],j);
            }
        }
    }
    for(i=1;i<=n;i++) next[i][0]=next[i][26];
    for(k=1;k<20;k++)
        for(i=1;i<=n;i++)
            if(next[i][k-1]==inf) next[i][k]=inf;
            else next[i][k]=next[next[i][k-1]+1][k-1];
    while(q--){
        scanf("%d%d",&i,&j);
        if(i==j) puts("No");
        else{
            for(k=19;k>=0;k--)
                if(next[i][k]<=j)
                    i=next[i][k];
            puts(i==j?"Yes":"No");
        }
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:12:12: error: reference to 'next' is ambiguous
   12 |     memset(next,inf,sizeof(next));
      |            ^~~~
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:7:9: note:                 'int next [500010][27]'
    7 | int n,q,next[maxn][27];
      |         ^~~~
a.cc:12:28: error: reference to 'next' is ambiguous
   12 |     memset(next,inf,sizeof(next));
      |                            ^~~~
/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:7:9: note:                 'int next [500010][27]'
    7 | int n,q,next[maxn][27];
      |         ^~~~
a.cc:15:9: error: reference to 'next' is ambiguous
   15 |         next[i][idx(s[i])]=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:7:9: note:                 'int next [500010][27]'
    7 | int n,q,next[maxn][27];
      |         ^~~~
a.cc:18:16: error: reference to 'next' is ambiguous
   18 |             if(next[i][k-1]<inf){
      |                ^~~~
/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:7:9: note:                 'int next [500010][27]'
    7 | int n,q,next[maxn][27];
      |         ^~~~
a.cc:19:19: error: reference to 'next' is ambiguous
   19 |                 j=next[i][k-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:7:9: note:                 'int next [500010][27]'
    7 | int n,q,next[maxn][27];
      |         ^~~~
a.cc:20:19: error: reference to 'next' is ambiguous
   20 |                 j=next[j+1][k-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:7:9: note:                 'int next [500010][27]'
    7 | int n,q,next[maxn][27];
      |         ^~~~
a.cc:22:21: error: reference to 'next' is ambiguous
   22 |                     next[i][k]=min(next[i][k],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:7:9: note:                 'int next [500010][27]'
    7 | int n,q,next[maxn][27];
      |         ^~~~
a.cc:22:36: error: reference to 'next' is ambiguous
   22 |                     next[i][k]=min(next[i][k],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:7:9: note:                 'int next [500010][27]'
    7 | int n,q,next[maxn][27];
      |         ^~~~
a.cc:25:12: error: reference to 'next' is ambiguous
   25 |         if(next[i][26]<inf){
      |            ^~~~
/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:7:9: note:                 'int next [500010][27]'
    7 | int n,q,next[maxn][27];
      |         ^~~~
a.cc:27:19: error: reference to 'next' is ambiguous
   27 |                 j=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:7:9: note:                 'int next [500010][27]'
    7 | int n,q,next[maxn][27];
      |         ^~~~
a.cc:28:19: error: reference to 'next' is ambiguous
   28 |                 j=next[j+1][k];
      |                   ^~~~
/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:7:9: note:                 'int next [500010][27]'
    7 | int n,q,next[maxn][27];
      |         ^~~~
a.cc:30:21: error: reference to 'next' is ambiguous
   30 |                     next[i][k]=min(next[i][k],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:7:9: note:                 'int next [500010][27]'
    7 | int n,q,next[maxn][27];
      |         ^~~~
a.cc:30:36: error: reference to 'next' is ambiguous
   30 |                     next[i][k]=min(next[i][k],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:7:9: note:                 'int next [500010][27]'
    7 | int n,q,next[maxn][27];
      |         ^~~~
a.cc:34:23: error: reference to 'next' is ambiguous
   34 |     for(i=1;i<=n;i++) next[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:7:9: note:                 'int next [500010][27]'
    7 | int n,q,next[maxn][27];
      |         ^~~~
a.cc:34:34: error: reference to 'next' is ambiguous
   34 |     for(i=1;i<=n;i++) next[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:7:9: note:                 'int next [500010][27]'
    7 | int n,q,next[maxn][27];
      |         ^~~~
a.cc:37:16: error: reference to 'next' is ambiguous
   37 |             if(next[i][k-1]==inf) next[i][k]=inf;
      |                ^~~~
/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:7:9: note:                 'int next [500010][27]'
    7 | int n,q,next[maxn][27];
      |         ^~~~
a.cc:37:35: error: reference to 'next' is ambiguous
   37 |             if(next[i][k-1]==inf) next[i][k]=inf;
      |                                   ^~~~
/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:7:9: note:                 'int next [500010][27]'
    7 | int n,q,next[maxn][27];
      |         ^~~~
a.cc:38:18: error: reference to 'next' is ambiguous
   38 |             else next[i][k]=next[next[i][k-1]+1][k-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:7:9: note:                 'int next [500010][27]'
    7 | int n,q,next[maxn][27];
      |         ^~~~
a.cc:38:29: error: reference to 'next' is ambiguous
   38 |             else next[i][k]=next[next[i][k-1]+1][k-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:7:9: note:                 'int next [500010][27]'
    7 | int n,q,next[maxn][27];
      |         ^~~~
a.cc:38:34: error: reference to 'next' is ambiguous
   38 |