#P2336. [SCOI2012] 喵星球上的点名

    ID: 1312 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2012四川莫队各省省选AC 自动机后缀数组,SA

[SCOI2012] 喵星球上的点名

Description

a180285 was lucky to be selected as an exchange student from Earth to Planet Meow. He found the roll call before class very interesting.

Suppose there are nn Meowians in class, and each Meowian’s name consists of a surname and a given name. The teacher on Planet Meow will choose mm strings for roll call. Each time a string is read, if this string is a substring of a Meowian’s surname or given name, then that Meowian must respond.

However, the Meowians’ character encoding is so peculiar that it cannot be represented using ASCII. For convenience, a180285 decides to represent Meowian names as sequences of numbers.

Now, can you help a180285 count how many Meowians respond to each roll call, and after all mm roll calls, how many times each Meowian has responded?

Input Format

First, we define how strings on Planet Meow are given:

You are first given a positive integer ll, the length of the string, followed by ll integers. The ii-th integer aia_i denotes the ii-th character of the string.

The first line contains two integers nn and mm, the number of Meowians and the number of roll calls.
The next nn lines each contain two Planet Meow strings given as above, representing the ii-th Meowian’s surname and given name, respectively.
The next mm lines each contain one Planet Meow string, representing a string read by the teacher for roll call.

Output Format

For each string read by the teacher, output one line with a single integer indicating how many Meowians respond.
Then output, on the last line, nn space-separated integers; the ii-th integer is the number of times the ii-th Meowian has been called.

2 3
6 8 25 0 24 14 8 6 18 0 10 20 24 0
7 14 17 8 7 0 17 0 5 8 25 0 24 0
4 8 25 0 24
4 7 0 17 0
4 17 0 8 25

2
1
0
1 2

Hint

Sample 1 Explanation

In fact, if the sample is translated into Earth language, it can be viewed as follows:

2 3
izayoi sakuya
orihara izaya
izay
hara
raiz

Constraints

  • For 30%30\% of the testdata, it is guaranteed that n,m103n, m \le 10^3, the total length of Meowian names does not exceed 4×1034 \times 10^3, and the total length of roll call strings does not exceed 2×1032 \times 10^3.
  • For 100%100\% of the testdata, it is guaranteed that 1n5×1041 \leq n \le 5 \times 10^4, 1m1051 \leq m \le 10^5, the total length of Meowian names and the total length of roll call strings do not exceed 10510^5 respectively, and the numbers that appear as characters in Meowian strings are at most 10410^4.

Translated by ChatGPT 5