#P9202. 「GMOI R2-T2」猫耳小(加强版)

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

「GMOI R2-T2」猫耳小(加强版)

Background

The difference between this problem and the original problem is the constraints and the output format. In this version, n106n\le 10^6 and the value range is 10910^9. You need to output a 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 any natural numbers, such 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, and output one valid plan.

*\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 element of the sequence.

Output Format

The first line contains one integer, representing the minimum number of modified elements.

The second line contains nn integers, representing the modified sequence. You need to ensure that every number in the modified sequence is within [0,109]Z[0,10^9]\cap\Z.

5 2
1 0 1 3 0
2
1 1 1 3 2

Hint

Explanation of the sample

One possible plan 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 22 elements in total.

It can be proven that no better plan exists.


Scoring

This problem uses a special judge (Special Judge) for evaluation.

For each test point, if your minimum number of steps is correct, you can get 30%30\% of the score. Based on this, if your construction is also correct, you can get full marks.

Note: Even if you cannot output a construction, you still need to output nn integers on the second line according to the output format.


This problem uses bundled tests, with no subtasks.

For 100%100\% of the testdata, 1n1061\le n\le 10^6, 0k,ai1090\le k,a_i\le 10^9.

The I/O volume of this problem is large, so it is recommended to use fast I/O methods.

Translated by ChatGPT 5