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

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

「GMOI R2-T2」猫耳小

Background

The difference between this problem and the enhanced version is the Constraints and the output format. In this version, n≤5×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 n≤n\le k≤k\le ai≤a_i\le Special Property Corresponding Test Points Total Score
00 66 −- 1∼21\sim 2 1010
11 100100 5×1035\times 10^3 5×1035\times 10^3 3∼53\sim 5 2020
22 5×1035\times 10^3 11 6∼106\sim 10
33 5×1035\times 10^3 A\bf A 11∼1511\sim 15
44 −- 16∼2016\sim 20 3030

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

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

Translated by ChatGPT 5