当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6701:Make Rounddog Happy

题目描述
Rounddog always has an array $a_1, a_2, \cdots, a_n$ in his right pocket, satisfying $1 \le a_i \le n$.

A subarray is a non-empty subsegment of the original array. Rounddog defines a good subarray as a subsegment $a_l, a_{l+1}, \cdots, a_r$ that all elements in it are different and $\max({a_l, a_{l+1}, \ldots, a_r}) - (r - l + 1) \leq k$.

Rounddog 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$.
输入解释
The input contains several test cases, and the first line contains a single integer $T~(1 \leq T \leq 20)$, the number of test cases.

The first line of each test case contains two integers $n~(1\leq n \le 300\,000)$ and $k~(1\leq k \le 300\,000)$.

The second line contains $n$ integers, the $i$-th of which is $a_i~(1 \le a_i \le n)$.

It is guaranteed that the sum of $n$ over all test cases never exceeds $1\,000\,000$.
输出解释
One integer for each test case, representing the number of subarrays Rounddog likes.
输入样例
2
5 3
2 3 2 2 5
10 4
1 5 4 3 6 2 10 8 4 5
输出样例
7
31
来自杭电HDUOJ的附加信息
Recommend chendu

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6701

最后修改于 2020-10-25T23:33:37+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/2000MS(Java/Others) 524288/524288K(Java/Others)