Restore Missing Values

Consider an array of ‘N’ integers which is indexed from ‘1’ to ‘N’. Exactly ‘Q’ queries numbered from ‘1’ to ‘Q’ are applied on them in increasing order. For the ‘i’-th query, an arbitrary range [L, R] of the array is selected (1 <= L <= R <= N) and each value from index ‘L’ to index ‘R’ gets changed to ‘i’. It is guaranteed that every index of the array is covered by at least one range.

This is a companion discussion topic for the original entry at