#P9199. 「GMOI R2-T2」猫耳小

    ID: 10262 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>贪心洛谷原创O2优化构造洛谷月赛

「GMOI R2-T2」猫耳小

Background

The difference between this problem and the enhanced version is the Constraints and the output format. In this version, n5×103n\le 5\times 10^3, and the value range is 5×1035\times 10^3. You do not need to output the construction.

Problem Description

Little R is a cute cat-eared girl. She likes studying the mex*\operatorname{mex}\text{*} of sequences.

Now she has a sequence aa of length nn. She hates the integer kk, so she wants to modify some elements of aa into arbitrary natural numbers, so that the mex\operatorname{mex} of every non-empty contiguous subarray of aa is not equal to kk.

Please find the minimum number of elements that need to be modified.

*\text{*} In this problem, the mex\operatorname{mex} of a sequence is defined as the smallest natural number that does not appear in the sequence. For example:

  • mex{1,2,3}=0\operatorname{mex}\{1,2,3\}=0, because 00 is a natural number.
  • mex{0,1,3}=2\operatorname{mex}\{0,1,3\}=2.
  • mex{0,1,2}=3\operatorname{mex}\{0,1,2\}=3.

Input Format

The first line contains two integers n,kn,k, representing the length of the sequence and the number that Little R hates.

The second line contains nn integers. The ii-th integer is aia_i, representing the ii-th term of the sequence.

Output Format

Output one integer in one line, representing the minimum number of elements to modify.

5 2
1 0 1 3 0
2

Hint

Sample Explanation

One possible way is to change {1,0,1,3,0}\{1,0,1,3,0\} into {1,1,1,3,2}\{1,1,1,3,2\}, modifying a total of two elements.

It can be proven that no better solution exists.


This problem uses Subtask bundled testdata.

Subtask nn\le kk\le aia_i\le Special Property Corresponding Test Points Total Score
00 66 - 121\sim 2 1010
11 100100 5×1035\times 10^3 5×1035\times 10^3 353\sim 5 2020
22 5×1035\times 10^3 11 6106\sim 10
33 5×1035\times 10^3 A\bf A 111511\sim 15
44 - 162016\sim 20 3030

Special Property A\bf A: It is guaranteed that ai<ka_i < k.

For 100%100\% of the testdata, 1n5×1031\le n\le 5\times 10^3, 0k,ai5×1030\le k,a_i\le 5\times 10^3.

Translated by ChatGPT 5