Inversion

Time Limit: 3000ms
Memory Limit: 65536KB
This problem will be judged on HDU. Original ID: 5497
64-bit integer IO format: %I64d      Java class name: Main

Description

You have a sequence $\{a_1,a_2,...,a_n\}$ and you can delete a contiguous subsequence of length $m$. So what is the minimum number of inversions after the deletion.

Input

There are multiple test cases. The first line of input contains an integer $T$, indicating the number of test cases. For each test case:

The first line contains two integers $n, m (1 \le n \le 10^5, 1 \le m < n)$ - the length of the seuqence. The second line contains $n$ integers $a_1,a_2,...,a_n (1 \le a_i \le n)$.

The sum of $n$ in the test cases will not exceed $2 \times 10^6$.

Output

For each test case, output the minimum number of inversions.

Sample Input

2
3 1
1 2 3
4 2
4 1 3 2

Sample Output

0
1

Source

Language: 
Theme: 
Share Code? 

Powered by NB231 | Current Style: .