LOJ 6092

这个题也很没意思

发现q那么大没有用,

不重复的询问有26*n种

所以记录一下就好了

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;++i)
#define For(i,a,b) for(int i=(a),i##_end=(b);i<i##_end;++i)
#define per(i,a,b) for(int i=(b),i##_st=(a);i>=i##_st;--i)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define dbg(x) cerr<<#x" = "<<x<<endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define Es(x,i) for(Edge *i=G[x];i;i=i->nxt)
typedef long long ll;
typedef pair<int,int> pii;
const int inf=~0u>>1,MOD=1e9+7;
inline int rd() {
    int x,c,f=1;while(!isdigit(c=getchar()))f=c!='-';x=c-'0';
    while(isdigit(c=getchar()))x=x*10+c-'0';return f?x:-x;
}
const int N=1511,H=26;
char s[N];
int p[H][N],n;
inline int F(int a,int b){
	int&x=p[a][b];
	if(~x)return x;
	int l=1,r=0,c=0;
	while(r<=n){
		while(r<=n&&c<=b){
			if(++r<=n)c+=s[r]!=a;
		}
		x=max(x,r-l);
		c-=s[l++]!=a;
	}
	return x;
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0);
	cin>>n>>s+1;
	rep(i,1,n)s[i]-='a';
	int q;cin>>q;
	memset(p,-1,sizeof p);
	while(q--){
		int x;
		char c;
		cin>>x>>c;
		cout<<F(c-'a',x)<<endl;
	}
}

  

转载于:https://www.cnblogs.com/limfc/p/8392754.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值