#C10052. Distinct Subarrays Counting
Distinct Subarrays Counting
Distinct Subarrays Counting
You are given an array of integers and several queries. Each query specifies an integer \(k\) representing the length of a subarray. Your task is to count the number of distinct subarrays of length \(k\) in the given array. A subarray is defined as a contiguous segment of the array, and two subarrays are considered distinct if their sequences of numbers differ.
Formally, for an array \(a_1,a_2,\dots,a_n\), the number of distinct subarrays of length \(k\) is given by $$\text{Count} = \left|\{(a_i, a_{i+1}, \dots, a_{i+k-1}) : 1 \le i \le n-k+1\}\right|.$$ Print the result for each query on the same line separated by spaces.
inputFormat
The first line of the input contains an integer \(T\) representing the number of test cases. Each test case consists of three lines:
- The first line contains two integers \(n\) and \(q\) denoting the number of elements in the array and the number of queries, respectively.
- The second line contains \(n\) space-separated integers representing the elements of the array.
- The third line contains \(q\) space-separated integers where each integer is a subarray length \(k\) for which you need to count distinct subarrays.
outputFormat
For each test case, output a single line with \(q\) integers separated by spaces. Each integer is the number of distinct subarrays of length \(k\) corresponding to a query.
## sample2
5 1
1 2 1 3 2
3
7 1
4 4 4 4 4 4 4
3
3
1
</p>