| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 1024 MB | 23 | 1 | 1 | 4.348% |
Little Y is a college student who is currently doing researches related to strings. Little Y learned about the following definitions regarding strings:
After understanding the above definitions, Little Y came up with the following problem:
Given a string $s[1 : n]$ of length $n,ドル there are $q$ queries, each query giving two parameters $i$ and $r$. You need to find out how many values of $l$ satisfy the following conditions:
Little Y would like to ask for your help in solving this problem.
This problem has multiple test data sets.
The first line of the input contains two integers $c $ and $t,ドル which represent the test case number and the number of test data sets. $c = 0$ represents that this test case is a sample test.
Then, each set of test data is given as input in order. For each set of test data:
The first line of input contains two positive integers, $n$ and $q,ドル which represent the length of the string and the number of queries respectively.
The second line of input contains a string $s$ of length $n$ that only consists of lowercase letters.
Then $q$ lines follow, each containing two positive integers, $i$ and $r,ドル representing a query. It is guaranteed that $i+2r -1 \leq n$.
For each query of each set of test data, output a line containing an integer, representing the number of $l$s satisfying the requirements.
For all test data, it is guaranteed that: 1ドル \leq t\leq 5,1\leq n\leq 10^5,1\leq q\leq 10^5,1\leq i+2r-1\leq n$. The string $s$ only consists of lowercase letters.
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
For the first set of test data in the sample:
In all four cases, $s[i:i+l-1]$ is lexcicographically smaller than $R(s[i+l:i+2l-1]),ドル so the answer is 4ドル$.