3098: Hash killer II
Time limit:5 secMemory limit:128 mbsecSpecial Judge
Submit:66
Solved:22
[
Submit] [
Status] [
Discuss]
Description
The weather was good this day. The hzhwcmhf God gave vfleaking a question:
Here is a string s with a length of N. How many different substrings with a length of L are required.
Substrings are defined as consecutive segments such as S [L], s [L + 1], and... s [R.
The two strings are considered to be different when and only when the characters at a certain position are different.
Vfleaking I think this is not a hash bare question! Therefore, hash + sorting is written.
The hzhwcmhf gods naturally know that this is the number of <L + 1 in the height of the suffix array, that is, the number of nodes containing L in the length range represented by the suffix automatic machine, the number of nodes with the suffix tree depth of L.
However, the hzhwcmhf God looked at vfleaking and said it was very sweaty. So I tried to get rid of him.
Vfleaking uses the lexicographic hash.CodeIt is roughly as follows:
U64 val = 0;
For (INT I = 0; I <L; I ++)
Val = (Val * base + s [I]-'A') % MOD;
U64 is an unsigned int64 in the range of [0, 2 ^ 64 ).
Base is a constant. vfleaking determines its value based on the mood.
MoD is equal to 1000000007.
Vfleaking also obtained the base ^ L % mod, that is, dividing the L power of the base by the remainder of mod, so that the hash value of all the substrings with the length of l can be conveniently obtained.
Then, vfleaking sorts the hash values, de-Duplicates them, and calculates the number of different hash values. The result is the number of hash values.
ItsAlgorithmThe C ++ code of is as follows:
Typedef unsigned 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 certainly knows how to get stuck! But he wants to test you.
Input
No input.
Output
You need to output a set of data so that the vfleaking code is wa. We will use special judge to check whether your results are correct.
The numbers N and l separated by spaces in the first line.
The second line is a string with a length of N. It can only contain 'A '~ 'Z '.
1 <= n <= 10 ^ 5, 1 <= L <= n,
If it does not conform to the preceding format, it will be wa.
Do not have extra characters, which may lead to your wa.
Sample Input
No
Sample output
8 4
Buaabuaa
(Of course, this output will be wa)
Hint
If there are 23 or more people in a room, the probability of two people having the same birthday is greater than 50%.
Source
Vfleaking & hzhwcmhf
Birthday attack: If you randomly select n numbers, you can select the same number (regardless of RP broken) if you select √ N at most)
Similarly, the hash value of this question ranges from 0 to 1000000007.
Select 10 ^ 5 times
The only note is that the number of solutions exceeds Mod.
Otherwise, it is impossible to have two numbers with the same hash value.
# Include <cstdio> # include <cstdlib> # include <ctime> # include <cstring> # include <iostream> using namespace STD; # define maxn (100000) int n = maxn, L = 13; int main () {cout <n <<<'' <L <Endl; For (INT I = 1; I <= N; I ++) cout <char (RAND () % 26 + 'A'); cout <Endl; return 0 ;}