luogu#P9453. [ZSHOI-R1] 有效打击
[ZSHOI-R1] 有效打击
Background
Tired of fighting the original bosses, FyFive decided to make a Hollow Knight Mod Boss called “Successful Champion”.
Problem Description
Similar to the original Failed Champion, the Successful Champion also has a big armor that cannot be “healed by soul”. However, what makes the Successful Champion harder is that its armor can only be damaged with a specific striking pattern. A strike sequence that can deal damage is called an “effective strike”.
As the designer of this Mod Boss, FyFive set a “standard sequence” that can produce effective strikes. To reduce the difficulty of execution, an effective strike can be produced as long as the strike order is “similar” to the standard sequence. Here, “similar” means: for a strike sequence, if you scale the lengths of all consecutive blocks of identical strikes by the same factor, and can obtain another sequence, then the two sequences are said to be “similar”.
For example:
112244and111222444are similar.111333and13are also similar.226and226are also similar.33889and33388899are not similar.
Since the Boss is still in the stage of tuning the standard sequence, FyFive set the Boss’s HP to infinity. But then he cannot compute how many effective strikes his strike sequence produces under the current standard sequence by comparing the initial HP and the final HP. So please help FyFive.
Note: If it is possible to produce multiple effective strikes at the same time, then multiple effective strikes are indeed produced. For example, when the strike sequence is 11 and the standard sequence is 1, this strike sequence produces effective strikes, because the first 1 and the second 1 are both similar to the standard sequence, and 11 is also similar to the standard sequence. If the standard sequence is 11, there are also effective strikes. If the standard sequence is 12, then no effective strike is produced. Similarly, when the strike sequence is 6666 and the standard sequence is 66, then a total of effective strikes are produced.
Formally,
Definition: Let sequence be
$$\underbrace{AA...A}_{a_1个}\underbrace{BB...B}_{a_2个}\underbrace{CC...C}_{a_3个}...$$and sequence be
$$\underbrace{AA...A}_{b_1个}\underbrace{BB...B}_{b_2个}\underbrace{CC...C}_{b_3个}...$$where 。
If $\frac{a_1}{b_1}=\frac{a_2}{b_2}=\frac{a_3}{b_3}=...=k\ , k>0$, then and are called similar sequences to each other.
In particular, a sequence of length is not similar to any sequence.
It is not hard to prove that under this definition, similarity between sequences is transitive.
Given sequence , compute how many substrings are similar to the given sequence .
Input Format
The first line contains two integers .
The second line contains integers, representing the strike sequence , separated by spaces.
The third line contains integers, representing the standard sequence , separated by spaces.
Output Format
Output one positive integer in a single line, representing the total number of effective strikes.
7 3
6 7 6 6 6 5 4
6 6 6
7
8 6
4 4 2 2 4 4 2 2
4 4 4 4 2 2
2
8 7
3 3 3 2 2 2 1 1
3 3 3 2 2 2 1
1
Hint
Constraints:
| Test Point | n | m | Special Property |
|---|---|---|---|
| 1~2 | None | ||
| 3~4 | A | ||
| 5~6 | B | ||
| 7~10 | C | ||
For of the testdata, it is guaranteed that for all , ; and for all , .
For of the testdata, it is guaranteed that .
Special property A: It is guaranteed that 。
Special property B: It is guaranteed that there exists exactly one such that ,; and ,。
Special property C: It is guaranteed that in the 10th test point, , and in the other test points, there are no more than different lengths of consecutive blocks.
Translated by ChatGPT 5