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
#include <bits/stdc++.h>
#define mn 200009
#define ull unsigned long long
#define ll long long
#define mod 998244353
using namespace std;
int q, n, tab[mn], pot[mn], l, r, mid;
ll ha(const string & s){
    ll tot=1;
    ll pa=0, pb=0;
    for(char c:s){
        ll ptot=tot;
        if(c=='a'){ tot=(tot*2-pa)%mod; pa=ptot; }
        else{ tot=(tot*2-pb)%mod; pb=ptot; }
        // dodajemy nowe kombinacje odejmując starte
    }
    return (tot-1+mod)%mod;
    // jeden pusty zbiór
}
int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s;
    cin>>n>>q>>s;
    cout<<ha(s)<<"\n";
    int p; char a;
    while(q--){
        cin>>p>>a;
        --p;
        s[p]=a;
        cout<<ha(s)<<"\n";
    }
}