#P2336. [SCOI2012] 喵星球上的点名
[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 Meowians in class, and each Meowian’s name consists of a surname and a given name. The teacher on Planet Meow will choose 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 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 , the length of the string, followed by integers. The -th integer denotes the -th character of the string.
The first line contains two integers and , the number of Meowians and the number of roll calls.
The next lines each contain two Planet Meow strings given as above, representing the -th Meowian’s surname and given name, respectively.
The next 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, space-separated integers; the -th integer is the number of times the -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 of the testdata, it is guaranteed that , the total length of Meowian names does not exceed , and the total length of roll call strings does not exceed .
- For of the testdata, it is guaranteed that , , the total length of Meowian names and the total length of roll call strings do not exceed respectively, and the numbers that appear as characters in Meowian strings are at most .
Translated by ChatGPT 5
京公网安备 11011102002149号