#P14420. [JOISC 2014] 历史的研究 / Historical Research
[JOISC 2014] 历史的研究 / Historical Research
Problem Description
As a pioneer in the study of the history of the country of IOI, Professor Joy obtained a diary said to have been written by the inhabitants of the ancient country of IOI. Professor Joy plans to study the life of the ancient country of IOI by analyzing this diary, so he decides to investigate the events recorded in it.
The diary records the events that happened on each of consecutive days, and each event is classified into one of several types. The type of the event on day () is represented by the integer ; a larger value of means a larger scale of the event.
Professor Joy decides to analyze the diary in the following way:
- Choose several consecutive days among the days of the diary as the analyzed interval.
- For an event type , its "importance" is defined as (the number of events of type in the interval).
- Compute the importance of every event type and take the maximum.
You are asked by Professor Joy to write a program for the analysis. Given an analyzed interval, the program must find the maximum importance.
Problem
Given the event type of each of the days in the diary and queries representing intervals of the diary, write a program that finds, for each query, the maximum importance of the events in the corresponding interval.
Input Format
Read the following data from standard input:
- The first line contains two integers and , separated by a space. This means that the diary lasts days and that queries are given.
- The next line contains integers , separated by spaces, where () is the type of the event that happened on day .
- In each of the following lines, the -th line () contains two integers and (), separated by a space, meaning that the interval of the -th query is from day to day .
Output Format
Output lines to standard output. The -th line () contains one integer, the maximum importance of the events in the interval of the -th query.
5 5
9 8 7 8 9
1 2
3 4
4 4
1 4
2 4
9
8
8
16
16
8 4
9 9 19 9 9 15 9 19
1 4
4 6
3 5
5 8
27
18
19
19
12 15
15 9 3 15 9 3 3 8 16 9 3 17
2 7
2 5
2 2
1 12
4 12
3 6
11 12
1 7
2 6
3 5
3 10
7 10
1 4
4 8
4 8
18
18
9
30
18
15
17
30
18
15
18
16
30
15
15
Hint
Sample 1 Explanation
- This diary lasts days, and the event types recorded in the diary are only , and .
- From day to day , the importance of event type is , the importance of event type is , and the importance of event type is , so the maximum of the three is .
- From day to day , the importance of event type is , the importance of event type is , and the importance of event type is , so the maximum of the three is .
- On day , the importance of event type is , the importance of event type is , and the importance of event type is , so the maximum of the three is .
- From day to day , the importance of event type is , the importance of event type is , and the importance of event type is , so the maximum of the three is .
- From day to day , the importance of event type is , the importance of event type is , and the importance of event type is , so the maximum of the three is .
Constraints
All input data satisfy the following conditions:
- .
- .
- ().
Subtasks
Subtask 1 [ points]
The following conditions are satisfied:
- .
- .
Subtask 2 [ points]
The following conditions are satisfied:
- .
- .
Subtask 3 [ points]
There are no satisfying (where , and ).
Subtask 4 [ points]
No additional constraints.
Translated by QwenWork