Prefix Statistics
Submit solution
Points:
1
Time limit:
1.0s
Memory limit:
256M
Problem type
Allowed languages
C++, Python
Prefix Counting Problem
Given N strings S1, S2, …, SN, followed by M queries.
Each query provides a string T, and you need to count how many of the N strings are prefixes of T.
The total length of all input strings (Si and T) does not exceed 106.
All strings contain only lowercase English letters.
Input Format
- The first line contains two integers N and M.
- The next N lines each contain one string Si.
- The following M lines each contain one query string T.
Output Format
For each query, output an integer — the number of Si strings that are prefixes of the current T.
Print each answer on a separate line.
Data Range
1 ≤ N, M ≤ 105
Sample Input
3 2
ab
bc
abc
abc
efg
Sample Output
2
0
Comments