#P10479. 匹配统计

匹配统计

Problem Description

Axuan wrote two strings on paper, denoted as AA and BB. Using what he learned in data structures and algorithms class, he can easily compute, for any starting position in string AA, the matching length between the suffix substring starting from that position and string BB.

However, Axuan is a hardworking and curious student, and he asks you QQ questions. In each question, he gives you an integer XX. You need to tell him how many starting positions satisfy that the matching length between the suffix substring of AA starting at that position and BB is exactly XX.

For example: A=aabcdeA=\text{aabcde}, B=abB=\text{ab}. Then AA has 66 suffix substrings: aabcde\text{aabcde}, abcde\text{abcde}, bcde\text{bcde}, cde\text{cde}, de\text{de}, e\text{e}. Their matching lengths with B=abB=\text{ab} are 1,2,0,0,0,01,2,0,0,0,0. Therefore, in AA, there are 44 positions whose matching length with BB is exactly 00, 11 position whose matching length is exactly 11, and 11 position whose matching length is exactly 22.

Input Format

The first line contains three integers N,M,QN, M, Q, representing the length of string AA, the length of string BB, and the number of queries.

The second line is string AA, and the third line is string BB.

In the next QQ lines, each line contains one integer xx, representing one query.

Output Format

Output QQ lines. Each line is the answer to the corresponding query, in order.

6 2 5
aabcde
ab
0
1
2
3
4
4
1
1
0
0

Hint

Constraints: 1N,M,Q,X2000001\leq N, M, Q, X\leq 200000

Translated by ChatGPT 5