26.10.4
T3
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
using namespace std;
const int N=1e6+10,maxl=1e3+10,inf=0x3f3f3f3f3f3f,mod=1e9+7;
int n;
string s;
int tot(string x,string y)
{
int res=0;
if(y[0]==y[1])
{
for(int i=0;i<x.size();i++) res+=(x[i]==y[0]);
return res;
}
bool flag=(x[0]==y[0]);
for(int i=1;i<s.size();i++)
{
if(flag && x[i]==y[1])
{
res++;
flag=false;
}
else if(x[i]==y[0]) flag=true;
}
return res*2;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin>>n;
while(n--)
{
cin>>s;
if(s.size()<=2)
{
cout<<"0\n";
continue;
}
int ans=0;
for(char i='0';i<='9';i++)
{
for(char j='0';j<='9';j++)
{
string t="";
t+=i;
t+=j;
ans=max(ans,tot(s,t));
}
}
cout<<s.size()-ans<<"\n";
}
return 0;
}T4
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
using namespace std;
const int N=1e6+10,maxl=1e3+10,inf=0x3f3f3f3f3f3f,mod=1e9+7;
int k,q;
int dp[N];
string s;
char t[N];
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin>>k>>s;
k=(1<<k);
for(int i=1;i<=k-1;i++) t[k-i]=s[i-1];
for(int i=k;i<=2*k-1;i++) dp[i]=1;
for(int i=k-1;i>=1;i--)
{
if(t[i]=='0') dp[i]=dp[2*i+1];
else if(t[i]=='1') dp[i]=dp[2*i];
else dp[i]=dp[2*i]+dp[2*i+1];
}
cin>>q;
while(q--)
{
int x;
char c;
cin>>x>>c;
int v=k-x;
t[v]=c;
while(v>=1)
{
if(t[v]=='0') dp[v]=dp[2*v+1];
else if(t[v]=='1') dp[v]=dp[2*v];
else dp[v]=dp[2*v]+dp[2*v+1];
v/=2;
}
cout<<dp[1]<<"\n";
}
return 0;
}