UVALive 6711(2013长春区域赛)

Given a string S and two integers L and M, we consider a substring of S as “recoverable” if and only
if
(i) It is of length M ∗ L;
(ii) It can be constructed by concatenating M “diversified” substrings of S, where each of these
substrings has length L; two strings are considered as “diversified” if they don’t have the same
character for every position.
Two substrings of S are considered as “different” if they are cut from different part of S. For
example, string “aa” has 3 different substrings “aa”, “a” and “a”.
Your task is to calculate the number of different “recoverable” substrings of S.
Input
The input contains multiple test cases, proceeding to the End of File.
The first line of each test case has two space-separated integers M and L.
The second ine of each test case has a string S, which consists of only lowercase letters.
The length of S is not larger than 105
, and 1 ≤ M ∗ L ≤ the length of S.
Output
For each test case, output the answer in a single line.
Sample Input
3 3
abcabcbcaabc
Sample Output
2

这题的正解应该是字符串HASH,我只想到了用后缀数组来实现

题目是要求找出一个M*L的子串,要求该子串中至少有两个长度的L的字符串不相同,问有多少种这种子串

先用后缀数组处理出所有后缀,我们可以先找相同的L长度的子串,这样对后缀数组for一遍即可标记处所有不满足的字符串,这个过程可以结合线段树查询来完成(我总觉得这么写多此一举,但当时又没想到好的方法,代码量多了好多),最后用所有的方案数减去不满足的数量即可

你可能感兴趣的:(ACM)