Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)
http://codeforces.com/contest/1023/problem/D
D. Array Restoration
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Initially there was an array a
consisting of n integers. Positions in it are numbered from 1 to n
.
Exactly q
queries were performed on the array. During the i-th query some segment (li,ri) (1≤li≤ri≤n) was selected and values of elements on positions from li to ri inclusive got changed to i. The order of the queries couldn't be changed and all q queries were applied. It is also known that every position from 1 to n
got covered by at least one segment.
We could have offered you the problem about checking if some given array (consisting of n
integers with values from 1 to q
) 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 0
.<