#P9461. 「EZEC-14」众数 II
「EZEC-14」众数 II
Background
dXqwq is an unlovely boy. In the mode problem of NOI2022, he defined std::deque and successfully got MLE.
Problem Description
Given a sequence of length , we construct a sequence in the following way:
- Initially, is an empty sequence.
- For , we append to the end of in order.
dXqwq defines the minimum mode of a sequence as the smallest value among all numbers with the maximum frequency. For example, the minimum mode of is , and the minimum mode of is .
You need to compute the sum of the minimum mode over every subarray of . Since the answer may be very large, output it modulo .
Input Format
The first line contains an integer .
The second line contains integers .
Output Format
Output one integer, representing the sum of the minimum mode over every subarray of modulo .
3
1 2 3
28
9
9 9 8 2 4 4 3 5 3
1912
Hint
[Sample Explanation]
In the first sample, .
There are subarrays whose minimum mode is , subarrays whose minimum mode is , and subarray whose minimum mode is . Therefore, the answer is .
[Hint]
Allocating std::deque will definitely cause MLE under a 512MB memory limit.
[Constraints]
This problem uses bundled testdata.
- Subtask 1 (10 pts): .
- Subtask 2 (20 pts): .
- Subtask 3 (20 pts): .
- Subtask 4 (10 pts): .
- Subtask 5 (20 pts): .
- Subtask 6 (10 pts): .
- Subtask 7 (10 pts): no special constraints.
For of the testdata, , .
Translated by ChatGPT 5