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:
typedef unsigned long long u64;
const int MAXN = 100000;
inline int hash_handle (const char *s, const int &n, const int &L, const int &base)
{
const int Mod = 1000000007;
U64 hash_pow_l = 1;
for (int i = 1; I <= l; i++)
hash_pow_l = (hash_pow_l * base)% Mod;
int li_n = 0;
static int LI[MAXN];
U64 val = 0;
for (int i = 0; i < L; i++)
val = (val * base + s[i]-' a ')% Mod;
li[li_n++] = val;
for (int i = l; i < n; i++)
{
val = (val * base + s[i]-' a ')% Mod;
val = (val + mod-((S[i-l]-' a ') * hash_pow_l)% mod)% MoD;
li[li_n++] = val;
}
Sort (Li, Li + li_n);
Li_n = Unique (Li, Li + li_n)-li;
return li_n;
}
HZHWCMHF of course know how to card! But he wants to test you.
Input
No input.
Output
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 InputNo
Sample Output8 4
Buaabuaa
(This output will be WA, of course)
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%.
Worship the Hzwer, VFK of the puzzle, and to study the string hash
The last hint was obvious, referring to the problem of the birthday paradox. The problem translates to a minimum of two in the number of 1000000007 , according to the principle of birthday attacks, up to the number of 1000000007^1/2 can appear the same number. Therefore, we can choose 10^5 as the value of N (no wonder the problem requires n maximum of 10^5) to achieve this goal.
In this case we just need to make sure the string entered is long enough (about 30 bits, not too long, of course.) I went to try test drive to 50 WA, so that the hash value of the string can be more than 1000000007 the modulus of the value. (This question seems to be the simplest problem in the hash Killer series ...) )
#include <iostream> #include <cstdio> #include <ctime> #include <cstdlib> #include <cstring > #include <cmath> #include <algorithm>using namespace Std;int n=100000,l=30;int main () {Cout<<n << ' <<l<<endl;for (int i=1;i<=n;i++) Cout<<char (rand ()%26+ ' a '); Cout<<endl;}
"BZOJ3098" Hash Killerⅱ