#P8306. 【模板】字典树 / Trie
【模板】字典树 / Trie
Problem Description
Given pattern strings and queries, each query provides a text string . For each query, please answer how many strings among satisfy that is a prefix of .
A string is a prefix of if and only if deleting some (possibly ) consecutive characters from the end of makes it equal to .
The input strings are case-sensitive. For example, the string Fusu is different from the string fusu.
Input Format
This problem contains multiple sets of testdata within a single test case.
The first line contains an integer , the number of test groups.
For each group, the format is as follows.
The first line contains two integers, representing the number of pattern strings and the number of queries .
The next lines each contain a string, representing a pattern string.
The next lines each contain a string, representing a query.
Output Format
Output the answers for each test group in the order of input.
For each query, output one integer per line as the answer.
3
3 3
fusufusu
fusu
anguei
fusu
anguei
kkksc
5 2
fusu
Fusu
AFakeFusu
afakefusu
fusuisnotfake
Fusu
fusu
1 1
998244353
9
2
1
0
1
2
1
Hint
Constraints
For all test points, it is guaranteed that , and the total length of all input strings does not exceed . The input strings contain only uppercase letters, lowercase letters, and digits, and there are no empty strings.
Notes
The standard solution uses cin/cout with synchronization disabled. This problem is not strict about constant factors.
Translated by ChatGPT 5