题目描述
The ugliness of a sequence of size N is defined as the number of pairs of neighboring elements which are not equal to each other. Formally, the ugliness of a sequence increase by 1 if for a value of i, 2 ≤ i ≤ N, the following condition holds true:
$A_{i} \neq A_{i-1}$.
Examples:
[1, 2, 2, 3], ugliness is 2.
[2, 1, 2, 3,4], ugliness is 4.
You are given a sequence A of length N consisting of the first K natural numbers only. Each of the first K natural numbers occur at least once in the given sequence. For each value of K, you are supposed to remove all of its occurrences from the original sequence and determine the ugliness of the resulting sequence.
Note: An empty sequence has ugliness of 0.
------ Input Format ------
- First line will contain T, the number of test cases. Then the testcases follow.
- Each testcase consist of two lines of input
- First line contains two integers N, K
- Second line contains N space-separated integers, where the i^{th} integer denotes the i^{th} element of the sequence A.
------ Output Format ------
- For each testcase print K space-separated integers denoting the answer for that testcase.
------ Constraints ------
$1 ≤ T ≤ 1000$
$1 ≤ K ≤ N ≤ 10^{5}$
- For each $i$, $1 ≤ A_{i} ≤ K$
- Every number from $1$ to $K$ appears atleast once
- Sum of N over all cases doesn't exceed $10^{5}$
----- Sample Input 1 ------
2
8 2
1 2 1 2 2 2 1 2
8 3
1 2 2 1 1 1 2 3
----- Sample Output 1 ------
0 0
1 1 3
----- explanation 1 ------
Test case 1:
- By removing 1, we get the sequence: $[2, 2, 2, 2, 2]$. Since all the elements are the same, ugliness is $0$
- By removing 2, we get the sequence: $[1, 1, 1]$. Since all the elements are the same, ugliness is $0$
Test case 2:
- By removing 1, we get the sequence: $[2, 2, 2, 3]$. Since the 3rd and 4th elements are not equal, ugliness is $1$.
- By removing 2, we get the sequence: $[1, 1, 1, 1, 3]$. Since the 3rd and 4th elements are not equal, ugliness is $1$.
- By removing 3, we get the sequence: $[1, 2, 2, 1, 1, 1, 2]$. Since 1st and 2nd, 3rd and 4th, 6th and 7th are not equal, total ugliness is $3$.
输入格式
见题面
输出格式
见题面