Cmostp
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述

There is a string S and q questions.

For each question , please print the number of distinct substrings who at least once end in the range .

We called a substring's end positions are the positions it ends in the string.

输入描述:

The first line contains two integers n,q (), indicating the length of the string S and the number of questions.

The second line contains a string S with length n containing only lowercase English letters.

In each of the next q lines, there are two integers l, r() describing a question.

输出描述:

q lines in total, each line should contain only one integer - the answer to the corresponding question.
示例1

输入

复制
6 6
aaaaaa
1 2
1 3
1 4
1 5
1 6
4 6

输出

复制
2
3
4
5
6
6
示例2

输入

复制
14 3
znloveloveqcjj
1 14
3 11
2 10

输出

复制
94
53
44

备注:

The index of a string in this problem starts from 1.

A substring of S can be obtained by removing zero or more(but not all) characters from the beginning and the end of S.