Make Rounddog Happy
Time limit2sMemory limit512 MB
Count subarrays whose elements are all distinct and whose maximum minus length is at most k, for arrays up to 300,000 with values bounded by n.
- Level
Hard9 of 10
- Topics
- Divide and conquer, Two pointers, Segment tree, Array
- Solved
- No attempts yet
Problem
Rounddog always carries an array in his right pocket, satisfying .
A subarray is a non-empty contiguous segment of the original array. Rounddog defines a good subarray as a segment in which all elements are distinct and .
Rounddog is not happy today. As his best friend, you want to find all good subarrays of to make him happy. For this problem, calculate the number of good subarrays of .
Input
The input contains several test cases. The first line contains a single integer (), the number of test cases.
The first line of each test case contains two integers () and ().
The second line contains integers, the -th of which is ().
The sum of over all test cases does not exceed .
Output
For each test case, print a single line with a single integer: the number of good subarrays in the given array.