#P4493. [HAOI2018] 字串覆盖
[HAOI2018] 字串覆盖
Description
Xiao C is quite into strings. He finds traditional string matching too boring, so he came up with the following problem.
For two strings of length , each time he gives four parameters . Let be the substring of from to (1-indexed), and let be the substring of from to . Then he performs the following operation:
If some substring of equals , we can cover this substring of and gain , where is the starting position of this substring in at the beginning (note: not in ), and is a given parameter. A position cannot be covered more than once. The covering operation can be performed any number of times. You need to output the maximum total gain.
Note that each query is independent, i.e., after finishing a query, the covered positions are restored.
Input Format
The first line contains two integers , denoting the string length and the parameter.
The next line contains a string .
The next line contains a string .
The next line contains an integer , denoting the number of queries.
Each of the next lines contains four integers , describing one query.
Output Format
Output lines, each containing one integer, the answer for each query.
10 11
abcbababab
ababcbabab
5
1 9 7 9
3 10 8 10
1 10 1 2
5 7 2 3
1 5 3 6
6
10
22
5
10
Hint
Explanation for Sample 1: 
For all testdata, , consist only of lowercase English letters, , , . HAOI2018 Round 1 T3.
For the testpoint with , the number of queries satisfying does not exceed , and are uniformly random.
Constraints

Translated by ChatGPT 5
京公网安备 11011102002149号