#P7458. [2017年杭电多校]Kanade's sum

[2017年杭电多校]Kanade's sum

Kanade's sum

Problem Description

Give you an array A[1..n]A[1..n] of length nn. Let f(l,r,k)f(l,r,k) be the k-th largest element of A[l..r]A[l..r]. Specially , f(l,r,k)=0f(l,r,k)=0 if rl+1<kr-l+1<k. Give you kk , you need to calculate l=1nr=lnf(l,r,k)\sum_{l=1}^{n}\sum_{r=l}^{n}f(l,r,k) There are T test cases. 1T101\leq T\leq 10 kmin(n,80)k\leq min(n,80) A[1..n] is a permutation of [1..n]A[1..n] ~is~a~permutation~of~[1..n] n5105\sum n\leq 5*10^5

Input

There is only one integer T on first line. For each test case,there are only two integers nn,kk on first line,and the second line consists of nn integers which means the array A[1..n]A[1..n]

Output

For each test case,output an integer, which means the answer.

Sample Input

1



5 2



1 2 3 4 5

Sample Output

30

Source

2017 Multi-University Training Contest - Team 3

https://acm.hdu.edu.cn/showproblem.php?pid=6058