#include <bits/stdc++.h>
#define ndl '\n'
#define ll long long
#define st first
#define nd second
#define debug(x) cout << #x << ": " << x << ndl
#define all(x) (x).begin(), (x).end()
using namespace std;
ll ile_takich(string s) {
vector<string> ans = {""};
for(ll i=0;i<s.size();i++) {
ll n = ans.size();
for(ll j=0;j<n;j++) {
ans.push_back(ans[j] + s[i]);
}
}
unordered_map<string, ll> hash;
for(auto x:ans) {
if(x!="") {
hash[x]++;
}
}
ll rozw = 0;
for(auto [a, b]:hash) {
// cout<<a<<" "<<b<<"\n";
if(b > 1) {
rozw++;
// cout<<a<<"\n";
}
}
return rozw;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
ll n, m; cin>>n>>m;
string s; cin>>s;
for(ll i=0;i<=m;i++) {
if(i>0) {
ll a; char b;
cin>>a>>b;
s[a-1] = b;
}
cout<<ile_takich(s)<<'\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 49 50 51 52 53 54 | #include <bits/stdc++.h> #define ndl '\n' #define ll long long #define st first #define nd second #define debug(x) cout << #x << ": " << x << ndl #define all(x) (x).begin(), (x).end() using namespace std; ll ile_takich(string s) { vector<string> ans = {""}; for(ll i=0;i<s.size();i++) { ll n = ans.size(); for(ll j=0;j<n;j++) { ans.push_back(ans[j] + s[i]); } } unordered_map<string, ll> hash; for(auto x:ans) { if(x!="") { hash[x]++; } } ll rozw = 0; for(auto [a, b]:hash) { // cout<<a<<" "<<b<<"\n"; if(b > 1) { rozw++; // cout<<a<<"\n"; } } return rozw; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll n, m; cin>>n>>m; string s; cin>>s; for(ll i=0;i<=m;i++) { if(i>0) { ll a; char b; cin>>a>>b; s[a-1] = b; } cout<<ile_takich(s)<<'\n'; } } |
English