Language: C++


#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define irep(i,a)for(int i=1;i<=a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll long long 
int n,q,ans;
string s;
char t,d;
int table[214514];
int hash[26][214514];
int pos[26];
int main(){
    cin>>n>>q>>s;
    rep(i,n)table[i]=1;

  rep(i,n){
    int tmp=s[i]-'A';
    hash[tmp][pos[tmp]]=i;
    pos[tmp]++;
  }

while(q--){
  cin>>t>>d;
  int tmp=t-'A';
    if(d=='R'){
      for(int i=pos[tmp]-1;i>=0;i--){
        //cout<<hash[tmp][i]<<endl;
        int cnt=table[hash[tmp][i]];
        table[hash[tmp][i]]=0;
        if(hash[tmp][i]==n-1)ans+=cnt;
        else table[hash[tmp][i]+1]+=cnt;
      }
    }
    if(d=='L'){
      for(int i=0;i<pos[tmp];i++){
            //    cout<<hash[tmp][i]<<endl;
        int cnt=table[hash[tmp][i]];
        table[hash[tmp][i]]=0;
        if(hash[tmp][i]==0)ans+=cnt;
        else table[hash[tmp][i]-1]+=cnt;
      }
      }
  }
cout<<n-ans<<endl;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:31:5: error: reference to 'hash' is ambiguous
   31 |     hash[tmp][pos[tmp]]=i;
      |     ^~~~
In file included from /usr/include/c++/14/string_view:50,
                 from /usr/include/c++/14/bits/basic_string.h:47,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:23:5: note:                 'int hash [26][214514]'
   23 | int hash[26][214514];
      |     ^~~~
a.cc:41:23: error: reference to 'hash' is ambiguous
   41 |         int cnt=table[hash[tmp][i]];
      |                       ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:23:5: note:                 'int hash [26][214514]'
   23 | int hash[26][214514];
      |     ^~~~
a.cc:42:15: error: reference to 'hash' is ambiguous
   42 |         table[hash[tmp][i]]=0;
      |               ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:23:5: note:                 'int hash [26][214514]'
   23 | int hash[26][214514];
      |     ^~~~
a.cc:43:12: error: reference to 'hash' is ambiguous
   43 |         if(hash[tmp][i]==n-1)ans+=cnt;
      |            ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:23:5: note:                 'int hash [26][214514]'
   23 | int hash[26][214514];
      |     ^~~~
a.cc:44:20: error: reference to 'hash' is ambiguous
   44 |         else table[hash[tmp][i]+1]+=cnt;
      |                    ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:23:5: note:                 'int hash [26][214514]'
   23 | int hash[26][214514];
      |     ^~~~
a.cc:50:23: error: reference to 'hash' is ambiguous
   50 |         int cnt=table[hash[tmp][i]];
      |                       ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:23:5: note:                 'int hash [26][214514]'
   23 | int hash[26][214514];
      |     ^~~~
a.cc:51:15: error: reference to 'hash' is ambiguous
   51 |         table[hash[tmp][i]]=0;
      |               ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:23:5: note:                 'int hash [26][214514]'
   23 | int hash[26][214514];
      |     ^~~~
a.cc:52:12: error: reference to 'hash' is ambiguous
   52 |         if(hash[tmp][i]==0)ans+=cnt;
      |            ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:23:5: note:                 'int hash [26][214514]'
   23 | int hash[26][214514];
      |     ^~~~
a.cc:53:20: error: reference to 'hash' is ambiguous
   53 |         else table[hash[tmp][i]-1]+=cnt;
      |                    ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:23:5: note:                 'int hash [26][214514]'
   23 | int hash[26][214514];
      |     ^~~~