#SRD0000084. Nghiên cứu lịch sử (Historical Research)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Nghiên cứu lịch sử (Historical Research)
Historical Research
Source: JOI
Version: Phuoc Hung OJ Extended
Problem Statement
A diary records days, with a positive integer event type on day . For an interval of consecutive days , the importance of type equals multiplied by its frequency in that interval. For every query interval, find the maximum importance over all event types. Queries do not modify the diary.
Input
The first line contains , the next line contains the positive event types , followed by inclusive 1-based intervals .
Output
For each query, output a 64-bit integer: the maximum importance, in input order.
Subtasks
-
Subtask 1 (5 points): ; . ; .
-
Subtask 2 (10 points): ; . ; .
-
Subtask 3 (25 points): ; . ; . Any two distinct query intervals must not be nested, i.e. there are no distinct with .
-
Subtask 4 (60 points): ; . ; .
Examples
Input
5 5
9 8 7 8 9
1 2
3 4
4 4
1 4
2 4
Output
9
8
8
16
16
Explanation
In , 9 and 8 each occur once, so the answer is 9. In , type 8 occurs twice and contributes , the maximum. Interval also contains two copies of 8, yielding 16.