F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Make Rounddog Happy

Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1140    Accepted Submission(s): 539


Problem Description
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$.
 

Input
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$.
 

Output
One integer for each test case, representing the number of subarrays Rounddog likes.
 

Sample Input
2 5 3 2 3 2 2 5 10 4 1 5 4 3 6 2 10 8 4 5
 

Sample Output
7 31
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-21 17:02:05, Gzip enabled