cswork / OA打开练习工作台

MetaOA #8

Longest Contiguous-House Segment After Each Build

估计中等可在线判题

考点(AI 标注)并查集哈希计数

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.

输入格式

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 the answer as described; separate multiple results with spaces in order, and output an empty line for an empty array.

样例 1

输入:

3
2 1 4

输出:

1 2 2

样例 2

输入:

4
1 3 0 4

输出:

1 1 2 2

样例 3

输入:

4
2 2 1 3

输出:

1 1 2 3

样例说明

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.