Codeforces814C 双指针

q<=2e5次查询 n<=1500
2e8 2s 迷之超时
长度为n的字符串 Q=3次查询 m=1 c=‘o’ 最多更改m次非c字符 问最长连续字符c有多长
6
koyomi
3
1 o
4 o
4 m

3
6
5

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
const ll mod=1e9+7;
const int INF=0x3f3f3f3f;
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define pb push_back
int T,n,k,q,ans,minn=INF;
int a[maxn];
string s;
ll m;
char c;
int main(){
	IO;
	cin>>n>>s;
	cin>>q;	
	while(q--){		
		cin>>m>>c;	
		int l=0,r=0,maxx=0,cnt=0;	
		for(r=0;r<n;r++)
		{			
			if(s[r]!=c)
			{				
				cnt++;						
			}			
			while(cnt>m)
			{				
				if(s[l]!=c)					
					cnt--;					
				l++;			
			}						
			maxx=max(maxx,r-l+1);	
		}		
		cout<<maxx<<endl;
	}	
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值