Restoring the Permutation Solution Codeforces Round #710 Div. 3

A permutation is a sequence of nn integers from 11 to nn, in which all numbers occur exactly once. For example, [1][1], [3,5,2,1,4][3,5,2,1,4], [1,3,2][1,3,2] are permutations, and [2,3,2][2,3,2], [4,3,1][4,3,1], [0][0] are not. Polycarp was presented with a permutation pp of numbers from 11 to nn. However, when Polycarp came home, he noticed that in his pocket, the permutation pp had turned into an array qq according to the following rule: qi=max(p1,p2,…,pi)qi=max(p1,p2,…,pi). Now Polycarp wondered what lexicographically minimal … Read more