Under construction

Still being built. Things may change

Good Subsegments

Time limit2sMemory limit2048 MB

Summary
For each k, count subsegments of length at least 2k whose first k elements are equal, whose last k elements are equal, and whose two end values match.
Level

Medium7 of 10

Topics
Hash map, Prefix sum, Array
Solved
No attempts yet

Statement

You are given an array a[1..n]a[1..n] of nn integers, each from 11 to nn. A subsegment a[ℓ..r]a[\ell..r] is its consecutive part from position ℓ\ell to position rr, inclusive.

A subsegment a[ℓ..r]a[\ell..r] is kk-good if all of the following hold:

  • r−ℓ+1≥2⋅kr - \ell + 1 \ge 2 \cdot k, so its length is at least 2⋅k2 \cdot k.
  • aℓ=aℓ+1=⋯=aℓ+k−1a_{\ell} = a_{\ell + 1} = \cdots = a_{\ell + k - 1}, so at least kk of its leftmost elements are equal.
  • ar=ar−1=⋯=ar−k+1a_{r} = a_{r - 1} = \cdots = a_{r - k + 1}, so at least kk of its rightmost elements are equal.
  • aℓ=ara_{\ell} = a_r, so its two ends are equal.

For each kk from 11 to ⌊n/2⌋\lfloor n/2 \rfloor, find the number of kk-good subsegments of aa.

Input

The first line contains an integer tt (1≤t≤5⋅1051 \le t \le 5 \cdot 10^5), the number of test cases. The test cases follow.

The first line of each test case contains an integer nn (2≤n≤5⋅1052 \le n \le 5 \cdot 10^5). The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤n1 \le a_i \le n).

The sum of nn over all test cases does not exceed 5⋅1055 \cdot 10^5.

Output

For each test case, print one line with ⌊n/2⌋\lfloor n/2 \rfloor integers. The kk-th integer is the number of kk-good subsegments.

Examples1

  1. Example 1

    Input
    4
    10
    1 2 2 2 2 2 3 2 2 2
    6
    1 1 1 2 1 1
    9
    2 2 1 1 1 2 2 1 1
    10
    3 2 3 2 4 2 10 10 10 10
    
    Expected output
    28 11 3 0 0
    10 2 0
    16 3 0 0
    10 1 0 0 0