#P15146. [SWERC 2025] LFS
[SWERC 2025] LFS
题目描述
You are designing the new videogame Live Fight Simulator. A level is defined by a string of length consisting of lowercase English letters, where each letter represents a type of enemy that appears in sequence.
To analyze the gameplay balance, you need to measure how repetitive different parts of the level are. You will consider specific contiguous segments of the level, with .
For each of these queries, you want to compute the length of the LFS (Longest Frequent Substring). Formally, for any string :
- let be the maximum frequency of any substring in ;
- let be the maximum length of a substring of that appears exactly times.
For each query , you must compute , which represents the maximum length among the most repetitive patterns of enemy spawns in that part of the level.
A string is a substring of a string if can be obtained from by the deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.
输入格式
The first line contains two integers (, ) — the length of the sequence and the number of level segments to analyze.
The second line contains a string of length consisting of lowercase English letters.
Each of the next lines contains two integers (), representing a query on the substring .
输出格式
Print lines. The -th line must contain a single integer: the value of for the pair .
5 4
ababa
1 1
1 5
1 4
2 5
1
1
2
2
10 1
aaaaaaaaaa
1 10
1
17 5
deabcabcabdeadede
1 8
1 10
4 9
2 16
1 17
3
2
3
1
2
提示
Explanation of sample 1.
In the first example:
- In the first query, the substring is . The maximum frequency of a substring inside is 1, reached by itself, whose length is 1. Therefore, the answer is 1.
- In the second query, the substring is . The maximum frequency of a substring inside is 3, reached by , whose length is 1. Therefore, the answer is 1.
- In the third query, the substring is . The maximum frequency of a substring inside is 2, reached by , and . Among these strings, the one with maximum length is , whose length is 2. Therefore, the answer is 2.
- In the fourth query, the substring is . The maximum frequency of a substring inside is 2, reached by , and . Among these strings, the one with maximum length is , whose length is 2. Therefore, the answer is 2.