Language: C++

//http://mujin-pc-2017.contest.atcoder.jp/tasks/mujin_pc_2017_c
#include <bits/stdc++.h>

using namespace std;

const int maxn = 500100;
const int maxj = 30;

int next[maxn][30],f[maxn][maxj],a[maxn],n,q;
string s;

int main() {
    ios_base::sync_with_stdio(0);
   // freopen("in.txt","r",stdin);
    cin>>s;
    int n = s.length();
    for (int i=0;i<n;i++) a[i] = s[i] - 'a';
    for (int i=0;i<=n;i++)
        for (int c=0;c<=26;c++)
            next[i][c]=-1;
    //cout<<"fuck"<<endl;
    for (int i=n-1;i>=0;i--) {
        next[i][a[i]] = i+1;
        for (int c=a[i]+1;c<=26;c++)
            if (next[i][c-1]!=-1) next[i][c] = next[next[i][c-1]][c-1];
        for (int c=0;c<a[i];c++)
            if (next[i][26]!=-1) next[i][c] = next[next[i][26]][c];
    }
  //  for (int i=0;i<n;i++) {
  //      for (int j=0;j<=26;j++) cout<<next[i][j]<<" ";
   //     cout<<endl;
  //  }
   // cout<<"fuck"<<endl;
    for (int i=0;i<=n;i++) f[i][0] = next[i][26];
    for (int j=1;j<maxj;j++)
        for (int i=0;i<=n;i++) {
            if (f[i][j-1]==-1) f[i][j]=-1;
            else f[i][j] = f[f[i][j-1]][j-1];
        }
    //cout<<"fuck"<<endl;
  //  for (int i=0;i<n;i++) {
   //     for (int j=0;j<maxj;j++) cout<<f[i][j]<<" ";
   //     cout<<endl;
  //  }
    cin>>q;
    int x,y;
    for (int i=1;i<=q;i++) {
        cin>>x>>y;
        x--;
       // cout<<x<<" "<<y<<endl;
        for (int j=maxj-1;j>=0;j--) {
            if (f[x][j]==-1) continue;
            if (f[x][j]<=y) {
                x = f[x][j];
            }
        }
       // cout<<x<<" "<<y<<endl;
        if (x>=y) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:20:13: error: reference to 'next' is ambiguous
   20 |             next[i][c]=-1;
      |             ^~~~
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:2:
/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:9:5: note:                 'int next [500100][30]'
    9 | int next[maxn][30],f[maxn][maxj],a[maxn],n,q;
      |     ^~~~
a.cc:23:9: error: reference to 'next' is ambiguous
   23 |         next[i][a[i]] = 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:9:5: note:                 'int next [500100][30]'
    9 | int next[maxn][30],f[maxn][maxj],a[maxn],n,q;
      |     ^~~~
a.cc:25:17: error: reference to 'next' is ambiguous
   25 |             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:9:5: note:                 'int next [500100][30]'
    9 | int next[maxn][30],f[maxn][maxj],a[maxn],n,q;
      |     ^~~~
a.cc:25:35: error: reference to 'next' is ambiguous
   25 |             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:9:5: note:                 'int next [500100][30]'
    9 | int next[maxn][30],f[maxn][maxj],a[maxn],n,q;
      |     ^~~~
a.cc:25:48: error: reference to 'next' is ambiguous
   25 |             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:9:5: note:                 'int next [500100][30]'
    9 | int next[maxn][30],f[maxn][maxj],a[maxn],n,q;
      |     ^~~~
a.cc:25:53: error: reference to 'next' is ambiguous
   25 |             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:9:5: note:                 'int next [500100][30]'
    9 | int next[maxn][30],f[maxn][maxj],a[maxn],n,q;
      |     ^~~~
a.cc:27:17: error: reference to 'next' is ambiguous
   27 |             if (next[i][26]!=-1) 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:9:5: note:                 'int next [500100][30]'
    9 | int next[maxn][30],f[maxn][maxj],a[maxn],n,q;
      |     ^~~~
a.cc:27:34: error: reference to 'next' is ambiguous
   27 |             if (next[i][26]!=-1) 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:9:5: note:                 'int next [500100][30]'
    9 | int next[maxn][30],f[maxn][maxj],a[maxn],n,q;
      |     ^~~~
a.cc:27:47: error: reference to 'next' is ambiguous
   27 |             if (next[i][26]!=-1) 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:9:5: note:                 'int next [500100][30]'
    9 | int next[maxn][30],f[maxn][maxj],a[maxn],n,q;
      |     ^~~~
a.cc:27:52: error: reference to 'next' is ambiguous
   27 |             if (next[i][26]!=-1) 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:9:5: note:                 'int next [500100][30]'
    9 | int next[maxn][30],f[maxn][maxj],a[maxn],n,q;
      |     ^~~~
a.cc:34:38: error: reference to 'next' is ambiguous
   34 |     for (int i=0;i<=n;i++) f[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:9:5: note:                 'int next [500100][30]'
    9 | int next[maxn][30],f[maxn][maxj],a[maxn],n,q;
      |     ^~~~