#P9109. [PA 2020] Tekstówka
[PA 2020] Tekstówka
Problem Description
This problem is translated from PA 2020 Round 4 Tekstówka.
Last year, during the PA held on a fan page of a certain social network, participants loudly asked us: “Where is the problem?”. This year, we decided to meet your expectations.
You are given two strings and consisting of lowercase English letters. Let denote the substring formed by the -th through the -th characters (inclusive) of in order. We define in the same way.
Your task is to process queries. Each query is given by four integers , where and . For each query, output the length of the longest common subsequence of the substring and the substring .
Note: A subsequence of a string is a string obtained by deleting some (possibly none) characters without changing the order of the remaining characters. For example, subsequences of can be or , but cannot be .
We call a common subsequence of strings and a subsequence that is both a subsequence of and a subsequence of .
We call the longest common subsequence of strings and the longest one among all common subsequences of and .
Input Format
The first line contains three integers , representing the lengths of strings and , and the number of queries.
The second line contains a string of length consisting of lowercase English letters.
The third line contains a string of length consisting of lowercase English letters.
The next lines each contain four integers , with the meaning as described above.
Output Format
Output lines, each containing one integer, the answer to the corresponding query.
5 6 7
abaab
babbaa
1 5 1 6
1 3 2 4
2 5 2 5
1 4 2 5
2 5 3 6
2 2 5 6
3 4 2 2
4
2
2
3
3
0
1
Hint
Constraints
This problem uses bundled testdata.
- For some subtasks, .
- For some other subtasks, .
- For some other subtasks, .
Among the above cases, at least one subtask is satisfied.
For of the testdata, it is guaranteed that , , , and .
Translated by ChatGPT 5