1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=998244353;
ll cntit(string s)
{
    ll n=s.size();
    ll siz=1;
    for(int i=0; i<n; i++)
        siz*=2;
    unordered_map<string, ll>se;
    for(int i=0; i<siz; i++)
    {
        string cur="";
        for(int j=0; j<n; j++)
        {
            if((1<<j)&i)
                cur+=s[j];
        }
        if(se.find(cur)==se.end())
            se[cur]=0;
        se[cur]++;
    }
    ll res=0;
    for(auto x:se)
    {
        if(x.second>=2)
            res=(res+1)%mod;
    }
    return res;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, q;
    cin>>n>>q;
    string s;
    cin>>s;
    cout<<cntit(s)<<"\n";
    for(int i=0; i<q; i++)
    {
        int cur;
        char c;
        cin>>cur>>c;
        s[cur-1]=c;
        cout<<cntit(s)<<"\n";
    }
}