Topic Links:
StringTime limit:2000/1000 MS (java/others)Memory limit:65536/65536 K (java/others)
Problem Description
Have a10\leq10≤ length\leq 1,000,000 ≤1< Span class= "mpunct" >,000,000 strings, consisting only of lowercase letters. Ask how many substrings, including at least k (1 \leq k \leq) k (1≤k≤ 26) a different letter?
Enter a description
The input contains multiple sets of data. The first line has an integert (1\leq t\leq) < Span class= "Strut bottom" >t (1≤t≤1< Span class= "Mord" >0s< Span class= "Strut bottom" >s. The second line enters an integer kk.
Output Description
For each set of data, the output meets the required number of substrings.
Input sample
2abcabcabca4abcabcabcabc3
Output sample
15T
Ideas:
The ruler to find the left border; the final mle of the game, the first is directly put down the status of each position, or while updating the boundary side update the number of letters better;
AC Code:
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<stack>#include<map>using namespaceStd;typedefLong Longll;Constll mod=1e9+7;Const intn=1e6+6;CharS[n];intnum1[ -],num2[ -];intK;intCheck () {intans=0; for(intI=0;i< -; i++) { if(num1[i]-num2[i]>0) {ans++; } } if(ans>=k)return 1; return 0;}intMain () {intT; scanf ("%d",&t); while(t--) {scanf ("%s", s); scanf ("%d",&k); intlen=strlen (s); memset (NUM1,0,sizeof(NUM1)); memset (num2,0,sizeof(num2)); intL=1, r=len+1; num1[s[0]-'a']++; ll ans=0; for(intI=1; i<=len;i++) { while(l<=len&&!Check ()) {L++; if(L<=len) num1[s[l-1]-'a']++; } num2[s[i-1]-'a']++; Ans+ = (ll) (R-l); } printf ("%i64d\n", ans); } return 0;}
hdu-5672 String (ruler)