Problem 3072 --Make Rounddog Happy

3072: Make Rounddog Happy

"
Time Limit $2$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $1$ 正确数量 $1$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签
Rounddog always has an array a1,a2,⋯,an in his right pocket, satisfying 1≤ai≤n.

A 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.

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≤T≤20), the number of test cases.

The first line of each test case contains two integers n (1≤n≤300000) and k (1≤k≤300000).

The second line contains n integers, the i-th of which is ai (1≤ai≤n).

It is guaranteed that the sum of n over all test cases never exceeds 1000000.
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

推荐代码 查看3072 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$938 $ms] 淡意的温柔 588053 2020-05-27 09:40:57
内存最少[$0 $KB] 淡意的温柔 588053 2020-05-27 09:40:57
第一AC 淡意的温柔 588053 2020-05-27 09:40:57
第一挑战 淡意的温柔 588053 2020-05-27 09:40:57

赛题来源/所属竞赛 2019 Multi-University Training Contest 10 N/A

竞赛编号 竞赛名称 竞赛时间 访问比赛