#CF2237F. 粉刷数组 / F. Paint the Array

    ID: 18580 传统题 2000ms 512MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>CodeforcesOrder Capital Round 2 (Codeforces Round 1104, Div. 1 + Div. 2)

粉刷数组 / F. Paint the Array

F. Paint the Array

Source: Codeforces 2237F
Contest: Order Capital Round 2 (Codeforces Round 1104, Div. 1 + Div. 2)
Time limit: 2 seconds
Memory limit: 256 megabytes

Statement

Consider an array of length nn, and a fixed integer mm. A painting operation is defined as follows:

  • Choose an interval of length mm and paint it with the values 1,2,,m1,2,\ldots,m from left to right. Formally, choose an integer ll such that 1lnm+11\le l\le n-m+1. Then, for every 1im1\le i\le m, position l+i1l+i-1 is painted with value ii.

If a position is painted multiple times, only the value painted most recently remains.

An array is called valid if it can be obtained by performing some painting operations such that every position is painted at least once.

Given an array a1,a2,,ana_1,a_2,\ldots,a_n with 1aim1\le a_i\le m, find the minimum number of modifications needed to make it valid. One modification changes one element to any integer between 11 and mm.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains two integers nn and mm (1mn51051\le m\le n\le 5\cdot 10^5) — the length of the array and the length of each painted interval.

The second line contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n (1aim1\le a_i\le m).

It is guaranteed that the sum of nn over all test cases does not exceed 51055\cdot 10^5.

Output

For each test case, output a single integer — the minimum number of modifications needed to make it valid.

Note

In the transformations below, the underlined positions are exactly the positions painted in the latest operation.

In the first test case, the array is already valid. It can be obtained by the following painting operations: $$ [-,-,-,-,-]\to[-,-,\underline{1},\underline{2},\underline{3}]\to[\underline{1},\underline{2},\underline{3},2,3]. $$ Therefore no modification is needed, and the answer is 00.

In the second test case, since n=4n=4 and m=3m=3, every valid array must be obtained by painting both intervals [1,3][1,3] and [2,4][2,4]. For example, $$ [-,-,-,-]\to[-,\underline{1},\underline{2},\underline{3}]\to[\underline{1},\underline{2},\underline{3},3]. $$ This gives the valid array [1,2,3,3][1,2,3,3]. The given array [1,2,2,3][1,2,2,3] can be changed into it by modifying only the third element, so the answer is 11.

In the third test case, one closest valid array is [1,1,2,3,3][1,1,2,3,3], which can be obtained as follows: $$ [-,-,-,-,-]\to[\underline{1},\underline{2},\underline{3},-,-]\to[1,2,\underline{1},\underline{2},\underline{3}]\to[1,\underline{1},\underline{2},\underline{3},3]. $$ The given array [2,1,2,3,2][2,1,2,3,2] differs from [1,1,2,3,3][1,1,2,3,3] in two positions. It can be proven that one modification is not enough, so the answer is 22.

Examples

15
5 3
1 2 3 2 3
4 3
1 2 2 3
5 3
2 1 2 3 2
5 3
2 2 2 2 2
5 4
1 1 3 4 1
6 3
1 1 1 2 1 1
8 5
1 2 1 2 3 4 5 1
5 3
2 3 1 1 2
8 4
1 2 3 2 3 2 3 4
4 4
4 3 2 1
5 1
1 1 1 1 1
7 3
3 3 3 2 1 1 1
10 3
1 2 3 1 2 2 3 1 2 3
7 3
1 3 2 3 2 1 2
10 4
1 4 3 3 2 3 4 4 2 2
0
1
2
3
2
2
1
4
2
4
0
4
1
3
4