Good Subsegments
Time limit2sMemory limit2048 MB
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 of integers, each from to . A subsegment is its consecutive part from position to position , inclusive.
A subsegment is -good if all of the following hold:
- , so its length is at least .
- , so at least of its leftmost elements are equal.
- , so at least of its rightmost elements are equal.
- , so its two ends are equal.
For each from to , find the number of -good subsegments of .
Input
The first line contains an integer (), the number of test cases. The test cases follow.
The first line of each test case contains an integer (). The second line contains integers ().
The sum of over all test cases does not exceed .
Output
For each test case, print one line with integers. The -th integer is the number of -good subsegments.