#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
map<string, ll> m;
void rekurencja(ll ind, string s, string curr, ll n){
if(ind == n){
m[curr]++;
return;
}
rekurencja(ind + 1, s, curr + s[ind], n);
rekurencja(ind + 1, s, curr, n);
return;
}
const ll M = 98244353;
void wypisz(string s){
ll w = 0;
for(auto u : m){
if(u.second > 1) w = (w + 1) % M;
}
m.clear();
cout << w << "\n";
return;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q;
cin >> n >> q;
string s;
cin >> s;
rekurencja(0, s, "", n);
wypisz(s);
int a;
char b;
for(int i = 0; i < q; ++i){
cin >> a >> b;
s[a-1] = b;
rekurencja(0, s, "", n);
wypisz(s);
}
return 0;
}
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 | #include <bits/stdc++.h> using namespace std; typedef long long ll; map<string, ll> m; void rekurencja(ll ind, string s, string curr, ll n){ if(ind == n){ m[curr]++; return; } rekurencja(ind + 1, s, curr + s[ind], n); rekurencja(ind + 1, s, curr, n); return; } const ll M = 98244353; void wypisz(string s){ ll w = 0; for(auto u : m){ if(u.second > 1) w = (w + 1) % M; } m.clear(); cout << w << "\n"; return; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, q; cin >> n >> q; string s; cin >> s; rekurencja(0, s, "", n); wypisz(s); int a; char b; for(int i = 0; i < q; ++i){ cin >> a >> b; s[a-1] = b; rekurencja(0, s, "", n); wypisz(s); } return 0; } |
English