QOJ.ac

QOJ

时间限制: 2 s 内存限制: 1024 MB 总分: 100

#9639. String

统计

Broken period

trade 100 string 0 book 0

So embarrassing

s t r i n g 0 s t r i n g 0 s t r i n g 0 s t r i n g 0 s t r i n g 0 s t r i

Only one last chance left

$R(s[i+l:i+2l-1])$ $R(s[i+l:i+2l-1])$ $R(s[i+l:i+2l-1])$ $R(s[i+l:i+2l-1])$ $R(s[i+l$ $R$ $R$ $R$ $R$ $r$ $r$ $r$ $r$

Cannot waste it anymore

2023.7

Given a string $s[1:n]$ of length $n$. There are $q$ queries, each given by two parameters $i$ and $r$. You need to find the number of $l$ such that the following conditions are satisfied:

  • $1 \le l \le r$.
  • $s[i:i+l-1]$ is lexicographically smaller than $s[i+l:i+2l-1]$.

Input

The first line contains an integer $c$, representing the subtask number. $c=0$ indicates that this test case is a sample.

The second line contains two positive integers $n, q$, representing the length of the string and the number of queries.

The third line contains a string $s$ of length $n$ consisting only of lowercase letters.

The next $q$ lines each contain two positive integers $i, r$, representing a query, guaranteed that $i + 2r - 1 \le n$.

Output

For each query, output a single integer on a new line representing the number of $l$ that satisfy the conditions.

Examples

Input 1

0
9 3
abacababa
1 4
2 4
3 3

Output 1

3
1
2

Constraints

For all data, $1 \le n, q \le 5 \times 10^5$, $1 \le i + 2r - 1 \le n$, and the string $s$ contains only lowercase letters.

Subtask Number Score Special Properties
$1$ $20$ $n, q \le 5 \times 10^3$
$2$ $10$ $n, q \le 10^5$, each character in $s$ is randomly generated from $a, b$
$3$ $20$ $n, q \le 10^5$
$4$ $20$ $n, q \le 3 \times 10^5$
$5$ $30$ No special restrictions

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.