#include <bits/stdc++.h>
#define ll long long
#define ve vector
#define fi first
#define se second
#define ld double
#define all(x) x.begin(), x.end()
using namespace std;
const int mod = 998244353;
const int MAXN = 5e4+10;
int calc(const string& st){
unordered_map<string, int> cnt;
for(int i = 1; i < (1 << st.size()); i++){
string cur;
for(int j = 0; j < st.size(); j++)
if((i >> j)&1)
cur += st[j];
cnt[cur]++;
}
int res = 0;
for(auto [st, c] : cnt)
res += c >= 2;
return res;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
string st;
cin >> st;
cout << calc(st) << "\n";
while(q--){
int a;
char c;
cin >> a >> c;
st[a - 1] = c;
cout << calc(st) << "\n";
}
}
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> #define ll long long #define ve vector #define fi first #define se second #define ld double #define all(x) x.begin(), x.end() using namespace std; const int mod = 998244353; const int MAXN = 5e4+10; int calc(const string& st){ unordered_map<string, int> cnt; for(int i = 1; i < (1 << st.size()); i++){ string cur; for(int j = 0; j < st.size(); j++) if((i >> j)&1) cur += st[j]; cnt[cur]++; } int res = 0; for(auto [st, c] : cnt) res += c >= 2; return res; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, q; cin >> n >> q; string st; cin >> st; cout << calc(st) << "\n"; while(q--){ int a; char c; cin >> a >> c; st[a - 1] = c; cout << calc(st) << "\n"; } } |
English