#P9482. [NOI2023] 字符串
[NOI2023] 字符串
Problem Description
Xiao Y is a college student who has recently been studying problems related to strings.
Xiao Y learned the following definitions about strings:
- Given a string of length , we define its substring () as the new string obtained by taking and concatenating them in order.
- Given a string of length , we define its reversed result as the string obtained by concatenating in order, i.e., reversing the string.
- Given two strings of length , we say is lexicographically smaller than if and only if there exists such that for all , , and .
After understanding the definitions above, Xiao Y came up with the following problem:
Given a string of length . There are queries, and each query gives two parameters . You need to find how many satisfy the following conditions:
- .
- is lexicographically smaller than .
Xiao Y asks you for help to solve this problem.
Input Format
This problem contains multiple test cases.
The first line of input contains two integers , representing the test point ID and the number of test cases. means this test point is the sample.
Then each test case is given as follows. For each test case:
The first line contains two positive integers , representing the string length and the number of queries.
The second line contains a string of length consisting only of lowercase letters.
The next lines each contain two positive integers , representing one query. It is guaranteed that .
Output Format
For each query in each test case, output one line with an integer, representing the number of that satisfy the conditions.
0 2
9 3
abacababa
1 4
2 4
3 3
9 3
abaabaaba
1 4
2 4
3 3
4
0
3
2
0
2
见附件中的 string/string2.in。
见附件中的 string/string2.ans。
见附件中的 string/string3.in。
见附件中的 string/string3.ans。
见附件中的 string/string4.in。
见附件中的 string/string4.ans。
Hint
[Sample Explanation #1]
For the first query of the first test case:
- When , , and .
- When , , and .
- When , , and .
- When , , and .
In all four cases, is lexicographically smaller than . Therefore, the answer is .
[Sample Explanation #2]
The Constraints of this sample satisfy test point .
[Sample Explanation #4]
The Constraints of this sample satisfy test points .
[Constraints]
For all testdata, it is guaranteed that: , , , , and the string consists only of lowercase letters.
| Test Point ID | Special Property | ||
|---|---|---|---|
| A | |||
| None | |||
| A | |||
| B | |||
| $$75,000$ | |||
| None | |||
Special property A: It is guaranteed that the string contains only characters and , and each character independently chooses between and with equal probability.
Special property B: It is guaranteed that adjacent characters in the string are all different.
On Luogu, in this problem, Subtask 1 contains hack data, and it is guaranteed that .
Translated by ChatGPT 5