"Topic link"
http://www.lydsy.com/JudgeOnline/problem.php?id=3620
Test instructions
Given a string, count the number of substrings such as A+b+a, which requires a>=k,b>=1.
Ideas
Enumerates the left endpoint I, the string s[i: N] Statistical answer.
Place a pointer, and then enumerate right endpoint J, if the pointer exceeds half the length, look forward along the fail and set the pointer to K. If the match satisfies the s[i. K]==S[J-K+1..J], finally determine the length limit.
Code
1#include <cstdio>2#include <cstring>3 using namespacestd;4 5typedefLong Longll;6 Const intN = 2e4+Ten;7 8 intn,k;9 ll ans;Ten One intF[n]; A CharS[n]; - - voidKMP (Char*s) { the intN=strlen (s+1); - intj=0, now=0; - for(intI=2; i<=n;i++) { - while(j&&s[j+1]!=s[i]) j=F[j]; + if(s[j+1]==s[i]) J + +; -f[i]=J; + A while(now&&s[now+1]!=s[i]) now=F[now]; at if(s[now+1]==s[i]) now++; - while(2*now>=i) now=F[now]; - if(now>=k) ans++; - } - } - intMain () in { -scanf"%s%d", s+2,&K); to intN=strlen (s+2); + for(intI=1; i<=n;i++) KMP (s+i); -printf"%lld\n", ans); the return 0; *}
Bzoj 3620 seems to have seen in a Dream (KMP)