#P4384. [八省联考 2018] 制胡窜
[八省联考 2018] 制胡窜
Description
For a string , define to denote the length of .
Next, define as the -th character of , and as the string formed by concatenating, from left to right, the -th through the -th characters of . In particular, if , or , or , we consider to be the empty string.
Given a string of length consisting only of digits, there are queries. In the -th query, a substring of is given. For this substring, count the number of pairs such that , , and occurs in or in or in .
Input Format
The first line contains two integers, the string length and the number of queries .
The second line contains a string of length consisting only of digit characters, representing .
Each of the next lines contains two positive integers and , indicating that the queried substring is .
Output Format
For each query, output a single integer on its own line representing the answer.
5 2
00100
1 2
1 3
5
1
Hint
| Test point | Other conditions | ||
|---|---|---|---|
| None | |||
| None | |||
| The string contains only . | |||
| None | |||
For all testdata, , , , and contains only digit characters.
Translated by ChatGPT 5
京公网安备 11011102002149号