AmazonOA #100
Buy Volumes (Order Books :)
Estimated EasyJudge-ready
Topics (AI-labelled)SimulationHashing
volumes is a permutation of 1..n, and on day i that volume arrives. Each day, buy as many new volumes as possible; before buying a volume you must already own every smaller volume number, and several volumes may be bought one after another on the same day. Output the volume numbers bought each day; if nothing is bought, output −1.
Input
The first line contains n (1..100000), and the second line contains the permutation volumes of 1..n.
Output
Output n lines; each line lists the volume numbers bought that day in ascending order, or −1 alone.
Example 1
Input:
4
2 1 4 3
Output:
-1
1 2
-1
3 4
Example 2
Input:
5
1 4 3 2 5
Output:
1
-1
-1
2 3 4
5
Example 3
Input:
3
1 2 3
Output:
1
2
3
Example notes
Example 1: output −1; 1 2; −1; 3 4 in order. Example 2: buy 1 on the first day, wait on the second and third days, buy 2 3 4 on day 4, and buy 5 on the last day. Example 3: the arrival order is already ascending, so each day buys that day's volume.
Editorial
Loading solution…