D题 通过率64% 求助

lst 记录每个Hash上次的位置 cnt 记录每个Hash 已有的个数

#include<map>
#include<string>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 1000017
#define ull unsigned long long
using namespace std;
map<ull,int>lst;map<ull,int>cnt;int n,m,k;ull mul[N];char s[N];
int main()
{
	scanf("%d%d%d",&n,&m,&k);scanf("%s",s+1);
	mul[0] = 1;
	for(int i = 1;i < m;i += 1)mul[i] = mul[i-1] * 131;
	int ans = 0;ull Hash = 0;
	for(int i = 1;i <= m;i += 1)Hash = Hash * 131 + s[i]-'0';
	cnt[Hash]++,lst[Hash] = m;
	if(cnt[Hash] == k)ans++;
	for(int i = m+1;i <= n;i += 1){
		Hash = Hash - mul[m-1]*(s[i-m]-'0');
		Hash = Hash * 131 + s[i]-'0';
		if(!cnt[Hash])cnt[Hash]++,lst[Hash] = i;
		else if(i-lst[Hash]+1 > m)cnt[Hash]++,lst[Hash] = i;
		if(cnt[Hash] == k)ans++;
		else if(cnt[Hash] > k)ans--;
	}
	printf("%d\n",ans);
	return 0;
}

全部评论

相关推荐

这是什么操作什么意思,这公司我服了...
斯派克spark:意思是有比你更便宜的牛马了
点赞 评论 收藏
分享
半解316:内容充实,细节需要修改一下。 1,整体压缩为一页。所有内容顶格。 2,项目描述删除,直接写个人工作量 修改完之后还需要建议,可以私聊
点赞 评论 收藏
分享
07-11 13:16
湖南工学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务