#P5357. 【模板】AC 自动机
【模板】AC 自动机
Background
This problem was originally called “Aho–Corasick Automaton (Second Enhanced Version)”. Before solving this problem, you may first solve Aho–Corasick Automaton (Easy Version) and Aho–Corasick Automaton (Easy Version II), which cover simpler applications of the Aho–Corasick automaton.
Problem Description
You are given a text string and pattern strings . Please find, for each pattern string , the number of times it appears in .
Input Format
The first line contains a positive integer , representing the number of pattern strings.
The next lines each contain a non-empty string consisting of lowercase English letters, where the -th line corresponds to .
The last line contains a non-empty string consisting of lowercase English letters.
The testdata does not guarantee that any two pattern strings are different.
Output Format
Output lines. The -th line contains a non-negative integer, representing the number of times appears in .
5
a
bb
aa
abaa
abaaa
abaaabaa
6
0
3
2
1
Hint
For of the data, , the total length of is at most , and the length of is at most .
Translated by ChatGPT 5