cswork / OAOpen practice workspace

MetaOA #8

Longest Contiguous-House Segment After Each Build

Estimated MediumJudge-ready

Topics (AI-labelled)Union-FindHashing

Houses are built one at a time at integer coordinates. After each operation, output the length of the longest run of consecutive integers among the occupied positions. Building again at an occupied position leaves the state unchanged.

Input

The first line contains n (1..100000), and the second line contains n positions (0..10⁹). A repeated position is treated as a set insertion and does not increase the number of houses.

Output

Output the answer as described; separate multiple results with spaces in order, and output an empty line for an empty array.

Example 1

Input:

3
2 1 4

Output:

1 2 2

Example 2

Input:

4
1 3 0 4

Output:

1 1 2 2

Example 3

Input:

4
2 2 1 3

Output:

1 1 2 3

Example notes

Example 1: houses are built at 2, 1, 4 in order. The longest runs are [2], [1,2], [1,2], with lengths 1, 2, 2.

Editorial

Loading solution…