{"trustable":false,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"MD","content":"Rounddog always has an array a1,a2,⋯,an in his right pocket, satisfying 1≤ai≤n.\n\nA subarray is a non-empty subsegment of the original array. Rounddog defines a good subarray as a subsegment al,al+1,⋯,ar that all elements in it are different and max(al,al+1,…,ar)−(r−l+1)≤k.\n\nRounddog is not happy today. As his best friend, you want to find all good subarrays of a to make him happy. In this case, please calculate the total number of good subarrays of a."}},{"title":"Input","value":{"format":"MD","content":"The input contains several test cases, and the first line contains a single integer T,(1 \u003c\u003d T \u003c\u003d 20), the number of test cases.\nThe first line of each test case contains two integers n,(1 \u003c\u003d n \u003c\u003d 300,000) and k,(1 \u003c\u003d k \u003c\u003d 300,000).\nThe second line contains n integers, (1 \u003c\u003d ai \u003c\u003d n).\nIt is guaranteed that the sum of n over all test cases never exceeds 1,000,000."}},{"title":"Output","value":{"format":"MD","content":"One integer for each test case, representing the number of subarrays Rounddog likes.\n\u003cbr\u003e"}},{"title":"Sample Input","value":{"format":"MD","content":"\u003cpre\u003e2\n5 3\n2 3 2 2 5\n10 4\n1 5 4 3 6 2 10 8 4 5\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"MD","content":"\u003cpre\u003e7\n31\u003c/pre\u003e"}}]}