← Home
write a go solution for F. We Be Summingtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a of length n and an integer k.Call a non-empty array b of length m epic if there exists an integer i where 1<=i<m and min(b_1,ldots,b_i)+max(b_i+1,ldots,b_m)=k.Count the number of epic subarrays^∗ of a.^∗An array a is a subarray of an array b if a can be obtained from b by the deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. InputThe first line contains an integer t (1<=t<=10^4) — the number of testcases.The first line of each testcase contains integers n and k (2<=n<=2*10^5; n<k<2*n) — the length of the array a and k.The second line of each testcase contains n integers a_1,a_2,ldots,a_n (1<=a_i<=n).The sum of n across all testcases does not exceed 2*10^5.OutputFor each testcase, output the number of epic contiguous subarrays of a.ExampleInput65 71 2 3 4 57 136 6 6 6 7 7 76 94 5 6 6 5 15 95 5 4 5 55 63 3 3 3 36 84 5 4 5 4 5Output2
12
3
8
10
4
NoteThese are all the epic subarrays in the first testcase:   [2,3,4,5], because min(2,3)+max(4,5)=2+5=7.  [3,4], because min(3)+max(4)=3+4=7. In the second test case, every subarray that contains at least one 6 and at least one 7 is epic.. Output only the code with no comments, explanation, or additional text.