#P16797. [蓝桥杯 2026 国 B] 密码提取
[蓝桥杯 2026 国 B] 密码提取
Problem Description
Xiao Lan found a digital password wall in some ruins. The password wall can be seen as a string of length , and the string contains only digits from to .
Xiao Lan can take any non-empty contiguous substring of and treat this substring as a decimal integer. Leading zeros are allowed, and any number of leading zeros does not affect the final value. If the substring consists entirely of digit , then no matter how long the substring is, its value is . For example, the values of and are both , and the values of and are both .
If two substrings have different start or end positions, then even if their values are the same, they are considered two different extraction plans.
Now Xiao Lan has attempts. In the -th attempt, a security threshold interval is given. For each attempt, please compute how many extraction plans make the extracted decimal value fall within .
Input Format
The first line contains two positive integers , representing the length of the digit string and the number of queries.
The second line contains a digit string of length .
The next lines each contain two integers , representing the security threshold interval of one query.
Output Format
Output lines. The -th line outputs one integer, representing the number of valid extraction plans for the -th query.
5 3
00510
0 5
1 10
50 510
8
5
6
Hint
Sample Explanation
The string is . If we count all non-empty contiguous substrings by their values, we get:
- Value : there are extraction plans for substring , and extraction plan for substring , for a total of plans.
- Value : there is extraction plan for substring .
- Value : the substrings , , and each have extraction plan, for a total of plans.
- Value : there is extraction plan for substring .
- Value : the substrings , , and each have extraction plan, for a total of plans.
- Value : the substrings , , and each have extraction plan, for a total of plans.
Therefore, the answer for interval is . The answer for interval is . The answer for interval is .
Constraints
For of the testdata, .
For of the testdata, .
For all testdata, , .
Translated by ChatGPT 5