Description
The weather is good this day, hzhwcmhf god Ben to vfleaking out a question:
Give you a string s of length n, and ask how many substrings of a different length are L.
The definition of a substring is s[l], S[l + 1] 、... S[R] Such a continuous paragraph.
Two strings are considered different when and only if the characters in a location are different.
Vfleaking see that this is not a hash of the naked problem! So decisively wrote the hash + sort.
and HZHWCMHF god Ben Heart naturally know, this problem is the suffix array height in the number of < L + 1, is the suffix of the machine on the length of the number of nodes containing L, is the suffix tree depth is the number of nodes.
But HZHWCMHF god Ben looked at Vfleaking's practice to show very sweat. So he wanted to get him off the cards.
Vfleaking uses a dictionary-ordered hash whose code is roughly the following:
U64 val = 0;
for (int i = 0; i < L; i++)
val = (val * base + s[i]-' a ')% Mod;
U64 is unsigned int64, the range is [0, 2^64).
Base is a constant, and vfleaking determines its value based on mood.
MoD equals 1000000007.
Vfleaking also found the base ^ l% mod, which is the L sub-division of the base divided by the remainder of the MoD, which makes it easy to find hashes of all substrings of length L.
The vfleaking then sorts the hashes, goes to the weight, and evaluates how many different hashes to use as the result.
The C + + code for its algorithm is as follows:
1typedef unsignedLong LongU64;2 3 Const intMAXN =100000;4 5InlineintHash_handle (Const Char*s,Const int&n,Const int&l,Const int&Base)6 {7 Const intMod =1000000007;8U64 hash_pow_l =1;9 for(inti =1; I <= l; i++)Tenhash_pow_l = (hash_pow_l *Base) %Mod; One A intLi_n =0; - Static intLI[MAXN]; - theU64 val =0; - for(inti =0; I < L; i++) -val = (Val *Base+ S[i]-'a') %Mod; -li[li_n++] =Val; + for(inti = l; I < n; i++) - { +val = (Val *Base+ S[i]-'a') %Mod; Aval = (val + Mod-((s[i-l)-'a') * hash_pow_l)% Mod)%Mod; atli[li_n++] =Val; - } - -Sort (Li, Li +li_n); -Li_n = Unique (Li, Li + li_n)-Li; - returnLi_n; in}
View Code
HZHWCMHF of course know how to card! But he wants to test you.
InputOutput
You need to output a set of data to make the Vfleaking code WA out. We will use special judge to check the correctness of your results.
The first line is two spaces separated by a number n, L.
The second line is a string of length n. Can only contain ' a ' ~ ' Z '.
Need to guarantee 1 <= n <= 10^5, 1 <= l <= N,
does not conform to the above format will WA.
Do not have extra characters, it is likely to cause you WA.
Sample InputSample Output8 4
Buaabuaa
(Of course, this output will be w-a)
HINT
If there are 23 or 23 people in a room, then at least two people have the same probability of having a birthday greater than 50%.
Source
Vfleaking & HZHWCMHF
Solution
Simply put, you can think of 1,000,000,007 hash values as 1,000,000,007 birthdays, so randomly constructing a very long string has a greater probability of making two different string hash values.
1#include <bits/stdc++.h>2 using namespacestd;3 Chars[100005];4 intMain ()5 {6 intn =100000, L = -;7Srand1);8 for(inti =0; I < n; i++)9S[i] = rand ()% -+'a';Tencout << N <<' '<< l << Endl <<s; One return 0; A}
View Code
[BZOJ3098] Hash Killer II