|
||||||||||
DanganronpaTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1690 Accepted Submission(s): 914 Problem Description Danganronpa is a video game franchise created and developed by Spike Chunsoft, the series' name is compounded from the Japanese words for "bullet" (dangan) and "refutation" (ronpa). Now, Stilwell is playing this game. There are $n$ verbal evidences, and Stilwell has $m$ "bullets". Stilwell will use these bullets to shoot every verbal evidence. Verbal evidences will be described as some strings $A_i$, and bullets are some strings $B_j$. The damage to verbal evidence $A_i$ from the bullet $B_j$ is $f(A_i,B_j)$. $$f(A,B)=\sum_{i=1}^{|A|-|B|+1}[~A[i...i+|B|-1]=B~]$$In other words, $f(A,B)$ is equal to the times that string $B$ appears as a substring in string $A$. For example: $f(ababa,ab)=2$, $f(ccccc,cc)=4$ Stilwell wants to calculate the total damage of each verbal evidence $A_i$ after shooting all $m$ bullets $B_j$, in other words is $\sum_{j=1}^m f(A_i,B_j)$. Input The first line of the input contains a single number $T$, the number of test cases. For each test case, the first line contains two integers $n$, $m$. Next $n$ lines, each line contains a string $A_i$, describing a verbal evidence. Next $m$ lines, each line contains a string $B_j$, describing a bullet. $T\leq 10$ For each test case, $n,m\leq 10^5$, $1\leq |A_i|,|B_j|\leq 10^4$, $\sum |A_i|\leq 10^5$, $\sum |B_j|\leq 10^5$ For all test case, $\sum |A_i|\leq 6*10^5$, $\sum |B_j|\leq 6*10^5$, $A_i$ and $B_j$ consist of only lowercase English letters Output For each test case, output $n$ lines, each line contains a integer describing the total damage of $A_i$ from all $m$ bullets, $\sum_{j=1}^m f(A_i,B_j)$. Sample Input
Sample Output
Author SXYZ Source | ||||||||||
|