#P3879. [TJOI2010] 阅读理解

    ID: 2816 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>字符串2010各省省选哈希,HASH概率论,统计字典树,Trie 树天津

[TJOI2010] 阅读理解

Description

The English teacher assigned NN reading-comprehension passages. Each passage contains many unfamiliar words that would require checking a dictionary. To save time, we want to collect statistics to determine in which passages certain words appear.

Input Format

The first line contains an integer NN, the number of passages. Each passage contains only spaces and lowercase letters.

The next NN lines each describe one passage. Each line begins with an integer LL, the number of words in that passage. Then follow LL words, separated by a single space.

Then an integer MM follows, the number of queries. After that, there are MM lines, each containing one word to query.

Output Format

For each query word, output one line listing the indices of the passages in which it appears, in ascending order, without duplicates. Indices are separated by a single space (note that there should be no space before the first index or after the last index). If the word never appears, output an empty line.

3
9 you are a good boy ha ha o yeah
13 o my god you like bleach naruto one piece and so do i
11 but i do not think you will get all the points
5
you
i
o
all
naruto

1 2 3
2 3
1 2
3
2

Hint

For 30%30\% of the testdata, 1M1031\le M\le 10^3.

For 100%100\% of the testdata, 1M1041\le M\le 10^4, 1N1031\le N\le 10^3.

Each passage length (including spaces between adjacent words) 5×103\le 5\times 10^3 characters, and each word length 20\le 20 characters.

Thanks to @钟梓俊 for adding a set of testdata.

Translated by ChatGPT 5