HDU 5056 Boring count

题解:前缀和计算统计。

#include <cstdio>
#include <cstring>
using namespace std;
typedef long long LL;
LL ans; char s[100010];
int T,k,t[200],i,j,n;
int main(){
    scanf("%d",&T);
    while(T--){
        scanf("%s%d",s,&k);
        n=strlen(s);
        for(i=1;i<200;i++)t[i]=0;
        for(ans=i=j=0;i<n;i++){
            if(i)t[s[i-1]]--;
            while(j<n&&t[s[j]]<k)t[s[j++]]++;
            ans+=(LL)(j-i);
        }printf("%I64d
",ans);
    }return 0;
}
原文地址:https://www.cnblogs.com/forever97/p/4024511.html