luogu#P9842. [ICPC2021 Nanjing R] Klee in Solitary Confinement
[ICPC2021 Nanjing R] Klee in Solitary Confinement
题目描述
Since the traveler comes, People in Monstadt suddenly raise great interest in computer programming and algorithms, including Klee, the Spark Knight of the Knights of Favonius.
Being sent to solitary confinement by Jean again, Klee decides to spend time learning the famous Mo's algorithm, which can compute with a time complexity of for some range query problem without modifications.
To check whether Klee has truly mastered the algorithm (or in fact making another bombs secretly), Jean gives her a problem of an integer sequence along with some queries requiring her to find the mode number in the contiguous subsequence . The mode number is the most common number (that is to say, the number which appears the maximum number of times) in the subsequence.
With the help of Mo's algorithm, Klee solves that problem without effort, but another problem comes into her mind. Given an integer sequence of length and an integer , you can perform the following operation at most once: Choose two integers and such that and add to every where . Note that it is OK not to perform this operation. Compute the maximum occurrence of the mode number of the whole sequence if you choose to perform (or not perform) the operation optimally.
输入格式
There is only one test case in each test file.
The first line of the input contains two integers and (, ) indicating the length of the sequence and the additive number.
The second line of the input contains integers () indicating the original sequence.
输出格式
Output one line containing one integer indicating the maximum occurrence of the mode number of the whole sequence after performing (or not performing) the operation.
题目大意
给定 和一个长为 的序列,你可以选择对区间 的数整体加上 ,也可以不加。最大化众数出现次数并输出。
5 2
2 2 4 4 4
5
7 1
3 2 3 2 2 2 3
6
7 1
2 3 2 3 2 3 3
5
9 -100
-1 -2 1 2 -1 -2 1 -2 1
3
提示
For the first sample test case, choose and and we'll result in the sequence . The mode number is obviously which appears times.
For the second sample test case, choose and and we'll result in the sequence . The mode number is which appears times.
For the fourth sample test case, choose not to perform the operation. The mode number is and which both appear times.