#P10634. BZOJ2372 music

    ID: 12108 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>字符串O2优化哈希 hashingKMP 算法

BZOJ2372 music

Problem Description

A war has recently broken out between countries A and B. dick, as the commander-in-chief of country A, has been having a headache about intelligence. This is because country B has recently hired a cryptography expert named Easy to encrypt all of their communications.

Easy likes singing very much, so he decided to store all signals as melodies. For example, 1155665443322111556654433221 could be a sequence of encrypted notes. We represent it with a sequence of the same length, which becomes 1,1,5,5,6,6,1,1,5,5,6,6,\dots. To increase confidentiality, he further adjusted the encrypted score by changing some pitches, turning the original sequence AA into BB, where A=B|A|=|B|, and for ai=aja_i=a_j we have bi=bjb_i=b_j, for ai<aja_i<a_j we have bi<bjb_i<b_j, and for ai>aja_i>a_j we have bi>bjb_i>b_j. For example, 11221 and 55775 may represent the same melody.

Recently, dick intercepted a signal that may contain important information. Based on past experience, dick already knows what some melodies mean. So dick wants to know: for a known melody, can we determine whether it appears in the intercepted melody? If it does, can we find how many times it appears and at which positions?

"Task": Determine the number of occurrences and the positions where the given melody appears in the intercepted melody.

Input Format

The first line contains three positive integers n,m,sn,m,s. nn is the length of the intercepted melody, mm is the length of the known melody. All melodies are positive integers in 1s(s25)1\sim s(s\leq 25).

The next nn lines each contain one integer describing the intercepted melody AA.

The next mm lines each contain one integer describing the known melody BB.

Output Format

The first line contains an integer tt, the number of occurrences.

Then output tt lines. In increasing order, give the starting position pp of each occurrence, i.e. A[pp+m1]A[p\dots p+m-1] is equivalent to BB.

9 6 10
5
6
2
10
10
7
3
2
9
1
4
4
3
2
1
1
3

Hint

For all testdata, it is guaranteed that 1n1051\leq n \leq 10^5, 1m250001\leq m \leq 25000

Translated by ChatGPT 5