atcoder#ARC069C. [ARC069E] Frequency
[ARC069E] Frequency
Score : points
Problem Statement
Snuke loves constructing integer sequences.
There are piles of stones, numbered through . The pile numbered consists of stones.
Snuke will construct an integer sequence of length , as follows:
- Among the piles with the largest number of stones remaining, let be the index of the pile with the smallest index. Append to the end of .
- Select a pile with one or more stones remaining, and remove a stone from that pile.
- If there is a pile with one or more stones remaining, go back to step 1. Otherwise, terminate the process.
We are interested in the lexicographically smallest sequence that can be constructed. For each of the integers , how many times does it occur in the lexicographically smallest sequence?
Constraints
Input
The input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the number of the occurrences of the integer in the lexicographically smallest sequence that can be constructed.
2
1 2
2
1
The lexicographically smallest sequence is constructed as follows:
- Since the pile with the largest number of stones remaining is pile , append to the end of . Then, remove a stone from pile .
- Since the piles with the largest number of stones remaining are pile and , append to the end of (we take the smallest index). Then, remove a stone from pile .
- Since the pile with the largest number of stones remaining is pile , append to the end of . Then, remove a stone from pile .
The resulting sequence is . In this sequence, occurs twice, and occurs once.
10
1 2 1 3 2 4 2 5 8 1
10
7
0
4
0
3
0
2
3
0