Kanade's sumTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2292 Accepted Submission(s): 945
Problem Description
Give you an array A[1..n]of
length n.
Let f(l,r,k) be the k-th largest element of A[l..r]. Specially , f(l,r,k)=0 if r−l+1<k. Give you k , you need to calculate ∑nl=1∑nr=lf(l,r,k) There are T test cases. 1≤T≤10 k≤min(n,80) A[1..n] is a permutation of [1..n] ∑n≤5∗105
Input
There is only one integer T on first line.
For each test case,there are only two integers n,k on first line,and the second line consists of n integers which means the array A[1..n]
Output
For each test case,output an integer, which means the answer.
Sample Input
Sample Output
f(l,r,K)表示区间l,r里面的K大值,问你所有连续子区间的f之和。 维护一个链表,从小到大遍历,每次寻找左边和右边最近k个比它大的数,就可以求出区间长度,然后删去此点,这样链表中存的都是比K大的数
不影响后面结果,需要遍历的点也就越来越少
删点时间复杂度O(1),遍历一点复杂度O(k),总时间复杂度O(nk)
|
HDU6069 Kanade's sum(链表+思路)
最新推荐文章于 2021-04-14 22:49:12 发布