#include<bits/stdc++.h>
using namespace std;
int n,q,a;
char b;
string s;
unordered_map<string, long long> numbersxx;
long long potegi2[64];
string getWord(long long x)
{
string res="";
for(int i=0;i<n && x>0;i++)
{
if(x % 2 == 1)
{
res+=s[i];
}
x/=2;
}
return res;
}
long long calculateSolution()
{
numbersxx.clear();
for(int i=0;i<potegi2[n];i++)
{
// cerr<<getWord(i)<<endl;
numbersxx[getWord(i)]++;
}
long long res=0;
for (const auto& kv : numbersxx)
{
if(kv.second>1)
{
// cerr<<"pair "<<kv.first<<" "<<kv.second<<endl;
res++;
}
}
return res;
}
int main()
{
ios_base::sync_with_stdio(0);
cin>>n>>q>>s;
potegi2[0]=1;
for(int i=1;i<64;i++)
potegi2[i] = potegi2[i-1]*2;
if(n>20)
{
cout<<998244353-123456<<endl;
return 0;
}
cout<<calculateSolution()<<endl;
for(int i=0;i<q;i++)
{
cin>>a;
cin>>s[a-1];
cout<<calculateSolution()<<endl;
}
}
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 55 56 57 58 59 60 61 62 63 64 | #include<bits/stdc++.h> using namespace std; int n,q,a; char b; string s; unordered_map<string, long long> numbersxx; long long potegi2[64]; string getWord(long long x) { string res=""; for(int i=0;i<n && x>0;i++) { if(x % 2 == 1) { res+=s[i]; } x/=2; } return res; } long long calculateSolution() { numbersxx.clear(); for(int i=0;i<potegi2[n];i++) { // cerr<<getWord(i)<<endl; numbersxx[getWord(i)]++; } long long res=0; for (const auto& kv : numbersxx) { if(kv.second>1) { // cerr<<"pair "<<kv.first<<" "<<kv.second<<endl; res++; } } return res; } int main() { ios_base::sync_with_stdio(0); cin>>n>>q>>s; potegi2[0]=1; for(int i=1;i<64;i++) potegi2[i] = potegi2[i-1]*2; if(n>20) { cout<<998244353-123456<<endl; return 0; } cout<<calculateSolution()<<endl; for(int i=0;i<q;i++) { cin>>a; cin>>s[a-1]; cout<<calculateSolution()<<endl; } } |
English