JOI Spring Training Camp 2013/14
Original Statement / Submission Site
A diary believed to have been written by inhabitants of ancient IOI Country has been delivered to Professor JOI, a leading researcher in the history of IOI Country. To study life in ancient IOI Country, Professor JOI has decided to investigate the events recorded in the diary.
The diary records exactly one event for each of N days. Events are classified into several types. The type of the event on day i is represented by the integer Xi. A larger value of Xi is considered to represent an event of greater scale.
Professor JOI will analyze the diary in the following way:
N days in the diary.t, define its importance as
t × (the number of events of type t during the selected period).You have been asked by Professor JOI to write a program for this analysis. Given a period to analyze, the program must determine the maximum importance among all event types.
Given the event types for the N days in the diary and Q queries, each representing a period in the diary, determine the maximum importance for each query.
The input is given from standard input in the following format:
N Q X1 X2 ... XN A1 B1 A2 B2 ... AQ BQ
N and Q, representing the number of days in the diary and the number of queries.N integers X1, ..., XN. The integer Xi represents the type of the event on day i.Q lines contains two integers Aj and Bj. The j-th query concerns the period from day Aj through day Bj, inclusive.Print Q lines.
On the j-th line, print the maximum importance for the j-th query.
1 ≤ N ≤ 1000001 ≤ Q ≤ 1000001 ≤ Xi ≤ 10000000001 ≤ Aj ≤ Bj ≤ NN ≤ 100Q ≤ 100N ≤ 5000Q ≤ 5000There do not exist distinct queries i and j such that
Ai ≤ Aj ≤ Bj ≤ Bi.
There are no additional constraints.
5 5 9 8 7 8 9 1 2 3 4 4 4 1 4 2 4
9 8 8 16 16
7 × 0 = 0, the importance of type 8 is 8 × 1 = 8, and the importance of type 9 is 9 × 1 = 9. Therefore, the maximum is 9.7 × 1 = 7, the importance of type 8 is 8 × 1 = 8, and the importance of type 9 is 9 × 0 = 0. Therefore, the maximum is 8.7 × 0 = 0, the importance of type 8 is 8 × 1 = 8, and the importance of type 9 is 9 × 0 = 0. Therefore, the maximum is 8.7 × 1 = 7, the importance of type 8 is 8 × 2 = 16, and the importance of type 9 is 9 × 1 = 9. Therefore, the maximum is 16.7 × 1 = 7, the importance of type 8 is 8 × 2 = 16, and the importance of type 9 is 9 × 0 = 0. Therefore, the maximum is 16.8 4 9 9 19 9 9 15 9 19 1 4 4 6 3 5 5 8
27 18 19 19
This input satisfies the constraints of Subtask 3.
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