欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1023D.Array Restoration
Array Restoration
Initially there was an array consisting of integers. Positions in it are numbered from to .
Exactly queries were performed on the array. During the -th query some segment was selected and values of elements on positions from to inclusive got changed to . The order of the queries couldn't be changed and all queries were applied. It is also known that every position from to got covered by at least one segment.
We could have offered you the problem about checking if some given array (consisting of integers with values from to ) 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 .
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.
Input
The first line contains two integers and () — the number of elements of the array and the number of queries perfomed on it.
The second line contains integer numbers () — the resulting array. If element at some position is equal to then the value of element at this position can be any integer from to .
Output
Print "YES" if the array can be obtained by performing queries. Segments are chosen separately for each query. Every position from to should be covered by at least one segment.
Otherwise print "NO".
If some array can be obtained then print integers on the second line — the -th number should be equal to the -th element of the resulting array and should have value from to . This array should be obtainable by performing exactly queries.
If there are multiple possible arrays then print any of them.
Note
In the first example you can also replace with but not with .
In the second example it doesn't really matter what segments to choose until query when the segment is .
The third example showcases the fact that the order of queries can't be changed, you can't firstly set to and after that change to . The segment of should be applied before segment of .
There is a lot of correct resulting arrays for the fourth example.
Samples
4 3
1 0 2 3
YES
1 2 2 3
3 10
10 10 10
YES
10 10 10
5 6
6 5 6 2 2
NO
3 5
0 0 0
YES
5 4 2
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |