#P10716. 【MX-X1-T4】「KDOI-05」简单的字符串问题
【MX-X1-T4】「KDOI-05」简单的字符串问题
Background
Original problem link: https://oier.team/problems/X1D.
Problem Description
You are given a string . There are queries. Each query gives . For each query, find how many non-empty strings exist such that there are (possibly empty) strings satisfying:
Here, denotes the prefix of with length .
Input Format
The first line contains a positive integer , denoting the length of .
The next line contains a string of length consisting only of lowercase letters, denoting .
The next line contains a positive integer .
The next lines each contain two positive integers, denoting a query .
Output Format
Output lines. Each line contains a non-negative integer, denoting the answer.
10
aabaacaaaa
5
5 3
5 2
6 1
10 4
10 5
1
2
1
2
1
10
bababababa
10
6 1
6 2
6 3
6 4
6 5
10 2
10 3
9 4
5 5
4 2
1
1
1
0
0
2
1
1
0
1
Hint
Sample Explanation #1
For the first query , we can take , , , where denotes the empty string. It can be proven that there is exactly one valid .
Constraints
This problem uses bundled testdata.
| Subtask ID | Score | Special Property | |
|---|---|---|---|
| None | |||
| Characters in are generated randomly from | |||
| All queries have the same | |||
| None | |||
For of the testdata: , , consists only of lowercase letters.
Translated by ChatGPT 5