Good Subsegments

시간 제한2초메모리 제한2048 MB

요약
각 k마다 왼쪽 k개와 오른쪽 k개 원소가 각각 같은 값이고 양 끝 값도 같은 부분 구간의 개수를 센다.
난이도

어려움10점 중 9점

유형
배열, 조합론, 수학, 구현
정답자
아직 제출이 없습니다

문제

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

A subsegment a\[ℓ..r]a\[\ell..r] is kk-good if the following conditions are satisfied:

  • r−ℓ+1≥2⋅kr - \ell + 1 \ge 2 \cdot k, so its length is at least 2⋅k2 \cdot k;
  • a_ℓ=a_ℓ+1=a_ℓ+2=...=a_ℓ+k−1a\_{\ell} = a\_{\ell + 1} = a\_{\ell + 2} = ... = a\_{\ell + k - 1}, so at least kk of its leftmost elements are equal to each other;
  • a_r=a_r−1=a_r−2=...=a_r−k+1a\_{r} = a\_{r - 1} = a\_{r - 2} = ... = a\_{r - k + 1}, so at least kk its rightmost elements are equal to each other;
  • a_ℓ=a_ra\_{\ell} = a\_r, so its ends are equal.

For each kk from 11 to ⌊n2⌋\left\lfloor\frac{n}{2}\right\rfloor, find the number of kk-good subsegments of the given array aa.

입력

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 consists of nn integers a_1,a_2,…,a_na\_1, a\_2, \ldots, a\_n (1≤a_i≤n1 \le a\_i \le n).

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

출력

For each test case, print a line with ⌊n2⌋\left\lfloor\frac{n}{2}\right\rfloor integers: the number of kk-good subsegments for each corresponding kk, starting from 11.

예제1

  1. 예제 1

    입력
    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
    
    예상 출력
    28 11 3 0 0
    10 2 0
    16 3 0 0
    10 1 0 0 0