"Bzoj 3097" Hash Killer I

Source: Internet
Author: User

3097:hash Killer I Time limit: 5 Sec Memory Limit: mbsec Special Judge
Submit: 382 Solved: 145
[Submit] [Status] 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 ';
U64 is unsigned int64, the range is [0, 2^64). Vfleaking let Val naturally overflow.
Base is a constant, and vfleaking determines its value based on mood.
Vfleaking also asks for the base ^ l, which is the L-second side of the base, so that the hash of all substrings of length l can be easily calculated.
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)
{
U64 hash_pow_l = 1;
for (int i = 1; I <= l; i++)
hash_pow_l *= Base;

int li_n = 0;
Static U64 LI[MAXN];

U64 val = 0;
for (int i = 0; i < L; i++)
val = val * base + s[i]-' a ';
li[li_n++] = val;
for (int i = l; i < n; i++)
{
val = val * base + s[i]-' a ';
Val-= (S[i-l]-' a ') * hash_pow_l;
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 output file has a total of two lines.
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

Orz Poles & fotile96 & Sillycross

Source

Vfleaking & HZHWCMHF



It's a very magical construction problem.


First understand two points:

1. The key to the card hash is to construct two different strings corresponding to the same hash value.


2. Burst U64 is equivalent to 2^64 this number to take the mold.


If base is even, then A.........AAA (>64 a) and BA.......AA (the number of a is the number of the preceding string a-1), the two strings of the same length, hash value is the same, obviously the string is different, so that the card off.


If base is odd, it's more troublesome.


Let's see VFK's approach:

If base is odd, now consider only a, B two letters.a \ b means that a can be divisible by B. (Orz specific mathematics)The mathematical function not (s) indicates that the ' a ' of each position in the string S becomes ' B ', and the ' B ' becomes a string formed after ' a '. For example not ("Ababaa") = "Bababb" stra. StrBrepresents a string concatenation. such as "Eva". "Haha" = "Wahaha"|str| represents the length of the string str. Set string Sequence {orzstr[i]},orzstr[1] = "A", orzstr[i] = orzstr[i-1]. Not (Orzstr[i-1]) so |orzstr[i]| = |orzstr[i-1]| * 2. Apparently this is geometric series, get: |orzstr[i]| = |orzstr[1]|. 2 ^ (i-1) = 2 ^ (i-1) set hash (str) to the value of Str. Then: Hash (orzstr[i]) = hash (orzstr[i-1]) * Base ^ |not (orzstr[i-1]) | + Hash (not (orzstr[i-1])) = hash (orzstr[i-1]) * Base ^ (2 ^ (i-2)) + hash (not (orzstr[i-1])) ha SH (not (orzstr[i])) =Hash (not (orzstr[i-1])) * Base ^ (2 ^ (i-2)) + hash (orzstr[i-1])Two-type subtraction:Hash (orzstr[i])-Hash (not (Orzstr[i]))= (Hash (orzstr[i-1]) * Base ^ (2 ^ (i-2)) + hash (not (orzstr[i-1)))-(Hash (not (orzstr[i-1])) * Base ^ (2 ^ (i-2)) + hash (orzstr[i-1 ))= (hash (orzstr[i-1])-Hash (not (orzstr[i-1))) * (base ^ (2 ^ (i-2))-1)It makes us realize thatHash (orzstr[i])-the hash (not (orzstr[i)) seems to be a magical thing. And our goal is actually to find two strings stra, STRB makesHash (stra)% 2^64 = hash (strB)% 2^64Quite with 2^64 \ Hash (stra)-hash (StrB) set sequence {F[i]},f[i] =Hash (orzstr[i])-Hash (not (Orzstr[i]))This will be: f[i] = f[i-1] * (base ^ (2 ^ (i-2))-1) Still a bit uncomfortable ah ... We'll setsequence {G[i]},g[i] =Base ^ (2 ^ (i-1))-1So can be written as: f[i] = f[i-1] * G[i-1] then f[i] = f[1] * g[1] * g[2] * ... * g[i-1] and discover a magical thing? Base is odd, then any positive integer of base must also be an odd number. So for any I must have g[i] is even, so 2 ^ (i-1) \ F[i] question is not the end of it ... Found no ... So we have to make 2 ^ f[i], at least let i = 65 ... Then found that |orzstr[65]| is an astronomical. We found out that we just analyzed too much of dad ... i > 1 o'clock: g[i] =Base ^ (2 ^ (i-1))-1 = (base ^ (2 ^ (i-2))-1) * (base ^ (2 ^ (i-2)) + 1) = g[i-1] * An even numberand G[1] is obviously even. Then 4 \ g[2],8 \ g[3] ... That is to say 2 ^ i \ G[i] so f[i] actually have: (2 ^ 1) * (2 ^ 2) * (2 ^ 3) * ... * (2 ^ (i-1)) \ f[i]2 ^ (i * (i-1)/2) \ F[i] When I take 12 o'clock, there is 6 6 of 2! This is the method when the card base is odd. ORZSTR[12] and not (orzstr[12]) is the request.

The read-in base has both an odd number and an even number, and adds 64 aces directly to the odd-numbered string.


#include <iostream> #include <cstring> #include <algorithm> #include <cstdio> #include < Cstdlib> #include <string>using namespace Std;char s[10000];int main () {cout<< (1<<11) +65<< "<< (1<<10) <<endl;int now=1;s[1]= ' a '; for (int. i=1;i<=11;i++) {for (int j=1;j<=now;j++) s[now+ j]=s[j]== ' a '? ' B ': ' a '; now<<=1;} for (int i=1;i<=now;i++) printf ("%c", S[i]), and for (int i=1;i<=65;i++) printf ("a");p rintf ("\ n"); return 0;}



Sentiment:

1. The key to this construction problem is to construct two strings and 2^64, then let two strings or two strings in the difference of more than 64 2 can be.


2. Other hash killer: VFK Blog

"Bzoj 3097" Hash Killer I

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.