#P8006. String Rearrangement in Phantom
String Rearrangement in Phantom
Description
Given a string , each query provides two substrings and . You need to count how many ways to split such that and . Here, means the reverse of string , means string concatenation, and means taking the -th to the -th characters of . Strings , , and can be empty.
Input Format
The first line contains two positive integers and , representing the length of and the number of queries.
The second line contains a string of length consisting of lowercase letters, representing .
The next lines each contain four positive integers , representing the query intervals. It is guaranteed that .
Output Format
Output lines, each containing one positive integer, representing the answer.
10 4
aabbaabbaa
1 6 5 10
3 6 5 8
1 3 5 7
1 10 1 10
11
9
2
17
Hint
This problem uses bundled testdata.
| Subtask ID | Score | Special Constraints |
|---|---|---|
| , |
For all testdata, it is guaranteed that , , , , and .
For Subtask , the time limit is seconds.
Translated by ChatGPT 5
京公网安备 11011102002149号