#C554. Longest Equal Subarray Lengths

    ID: 49200 Type: Default 1000ms 256MiB

Longest Equal Subarray Lengths

Longest Equal Subarray Lengths

Given an array of n integers, for each element you are to determine the length of the longest contiguous subarray in which every element is equal to that element. In other words, if the array is divided into blocks of consecutive equal numbers, then every element in the same block is replaced by the length of that block.

More formally, let \(a_1, a_2, \ldots, a_n\) be the array. For each index \(i\), find the largest interval \([l, r]\) such that \(l \le i \le r\) and for every \(j, k \in [l, r]\), \(a_j = a_k\). Then, the answer for index \(i\) is \(r - l + 1\).

For example, consider the array: [1, 3, 3, 2, 1, 3, 1]. The contiguous groups are [1], [3, 3], [2], [1], [3], [1]. Therefore, the corresponding output is [1, 2, 2, 1, 1, 1, 1].

inputFormat

The first line contains a single integer n representing the number of elements in the array.

The second line contains n space-separated integers representing the elements of the array.

outputFormat

Output a single line containing n space-separated integers, where the i-th integer is the length of the longest contiguous subarray (block) in which the i-th element is present. (i.e. the length of the contiguous group of equal numbers that contains the i-th element).

## sample
7
1 3 3 2 1 3 1
1 2 2 1 1 1 1