Examples
Input
6
koyomi
3
1 o
4 o
4 m
Output
3
6
5
Input
15
yamatonadeshiko
10
1 a
2 a
3 a
4 a
5 a
1 b
2 b
3 b
4 b
5 b
Output
3
4
5
7
8
1
2
3
4
5
Input
10
aaaaaaaaaa
2
10 b
10 z
Output
10
10
Note
In the first sample, there are three plans:
In the first plan, at most 1 piece can be repainted. Repainting the "y" piece to become "o" results in "kooomi", whose Koyomity of 3 is the best achievable;
In the second plan, at most 4 pieces can be repainted, and "oooooo" results in a Koyomity of 6;
In the third plan, at most 4 pieces can be repainted, and "mmmmmi" and "kmmmmm" both result in a Koyomity of 5.
题意:给出一个长度为 n 的小写字母构成的字符串,询问 q 次每当替换了 m 个非 c 字符后最大的连续 c 子串的长度。(c表示Koyomi可能喜欢的颜色)
**分析:一开始以为是不可以暴力的。看了题解之后发现状态原来那么少。。
然后用尺取就可以了。。。。。预处理一下**
int last[30];
int vis[30];
int dp[27][N];
int num[N];
int n;
int solve(int c,int k){
int ret=0;
int l=1,r=1;
int use=0;
int maxx=0;
while(l<=r&&r<=n){
while(use<=k&&l<=r&&r<=n){
ret=max(ret,maxx);
if(num[r]==c){maxx++;r++;}
else{use++;maxx++;r++;}
}
while(use>k&&l<=r){
if(num[l]==c){l++;maxx--;}
else{use--;l++;maxx--;}
}
ret=max(ret,maxx);
}
return ret;
}
void init(){
for(int c=0;c<=25;++c)
for(int k=1;k<=n;++k)
dp[c][k]=solve(c,k);
}
int main(){
//freopen("in.txt","r",stdin);
sf("%d",&n); sf("%s",s+1);
rep(i,1,n)num[i]=s[i]-'a';
init();
int q;sf("%d",&q);
rep(i,1,q){
int a;char c;sf("%d %c",&a,&c);
pf("%d\n",dp[c-'a'][a]);
}
}