CF1023D.Array Restoration

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Initially there was an array aa consisting of nn integers. Positions in it are numbered from 11 to nn .

Exactly qq queries were performed on the array. During the ii -th query some segment (li,ri)(l_i, r_i) (1lirin)(1 \le l_i \le r_i \le n) was selected and values of elements on positions from lil_i to rir_i inclusive got changed to ii . The order of the queries couldn't be changed and all qq queries were applied. It is also known that every position from 11 to nn got covered by at least one segment.

We could have offered you the problem about checking if some given array (consisting of nn integers with values from 11 to qq ) can be obtained by the aforementioned queries. However, we decided that it will come too easy for you.

So the enhancement we introduced to it is the following. Some set of positions (possibly empty) in this array is selected and values of elements on these positions are set to 00 .

Your task is to check if this array can be obtained by the aforementioned queries. Also if it can be obtained then restore this array.

If there are multiple possible arrays then print any of them.

输入格式

The first line contains two integers nn and qq ( 1n,q21051 \le n, q \le 2 \cdot 10^5 ) — the number of elements of the array and the number of queries perfomed on it.

The second line contains nn integer numbers a1,a2,,ana_1, a_2, \dots, a_n ( 0aiq0 \le a_i \le q ) — the resulting array. If element at some position jj is equal to 00 then the value of element at this position can be any integer from 11 to qq .

输出格式

Print "YES" if the array aa can be obtained by performing qq queries. Segments (li,ri)(l_i, r_i) (1lirin)(1 \le l_i \le r_i \le n) are chosen separately for each query. Every position from 11 to nn should be covered by at least one segment.

Otherwise print "NO".

If some array can be obtained then print nn integers on the second line — the ii -th number should be equal to the ii -th element of the resulting array and should have value from 11 to qq . This array should be obtainable by performing exactly qq queries.

If there are multiple possible arrays then print any of them.

输入输出样例

  • 输入#1

    4 3
    1 0 2 3
    

    输出#1

    YES
    1 2 2 3
    
  • 输入#2

    3 10
    10 10 10
    

    输出#2

    YES
    10 10 10 
    
  • 输入#3

    5 6
    6 5 6 2 2
    

    输出#3

    NO
    
  • 输入#4

    3 5
    0 0 0
    

    输出#4

    YES
    5 4 2
    

说明/提示

In the first example you can also replace 00 with 11 but not with 33 .

In the second example it doesn't really matter what segments to choose until query 1010 when the segment is (1,3)(1, 3) .

The third example showcases the fact that the order of queries can't be changed, you can't firstly set (1,3)(1, 3) to 66 and after that change (2,2)(2, 2) to 55 . The segment of 55 should be applied before segment of 66 .

There is a lot of correct resulting arrays for the fourth example.

首页