#P4062. [Code+#1] Yazid 的新生舞会
[Code+#1] Yazid 的新生舞会
Description
Yazid has a sequence of length , indexed from to . Obviously, this sequence has subarrays.
For any subarray , if the mode in this subarray has a frequency strictly greater than (that is, more than half of the subarray's length), then Yazid calls this subarray "Freshman Ball".
The mode is the value that appears most frequently in the subarray. In particular, if multiple values tie for the highest frequency, we define the smallest value as the mode.
Now Yazid wants to know how many subarrays are "Freshman Ball".
Input Format
The first line contains two space-separated nonnegative integers , representing the length of the sequence and the data type. The role of the data type will be explained in the Hint.
The second line contains space-separated nonnegative integers, namely , describing the sequence.
Output Format
Output a single integer on one line, representing the answer.
5 0
1 1 2 2 3
10
Hint
【Sample Explanation #1】
The "Freshman Ball" subarrays are $[1,1],[1,2],[1,3],[2,2],[2,4],[3,3],[3,4],[3,5],[4,4],[5,5]$, for a total of .

Constraints:
For all testdata, it is guaranteed that .
For testdata, there is no special stipulation.
For testdata, it is guaranteed that .
For testdata, it is guaranteed that the mode of sequence appears at most times in the entire sequence.
For testdata, it is guaranteed that .
From CodePlus 2017 November Contest, produced by the Student Algorithms and Competitions Association, Department of Computer Science and Technology, Tsinghua University.
Credit: idea/Zheng Linkai, problem setting/Wang Yuzhong, problem checking/Zheng Linkai.
Git Repo: https://git.thusaac.org/publish/CodePlus201711
Thanks to Tencent for supporting this contest.
Translated by ChatGPT 5
京公网安备 11011102002149号