CF1762F.Good Pairs
省选/NOI-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a consisting of n integers and an integer k.
A pair (l,r) is good if there exists a sequence of indices i1,i2,…,im such that
- i1=l and im=r;
- ij<ij+1 for all 1≤j<m; and
- ∣aij−aij+1∣≤k for all 1≤j<m.
Find the number of pairs (l,r) (1≤l≤r≤n) that are good.
给你一个包含 n 个整数的数组 a 和一个整数 k。
若存在一个下标序列 i1,i2,…,im,使得
- i1=l 且 im=r;
- 对所有 1≤j<m,有 ij<ij+1;且
- 对所有 1≤j<m,有 ∣aij−aij+1∣≤k,
则称二元组 (l,r) 是“好的”。
求满足 1≤l≤r≤n 的“好”的二元组 (l,r) 的个数。
输入格式
Each test contains multiple test cases. The first line contains a single integer t (1≤t≤105) — the number of test cases. The description of the test cases follows.
The first line of each test case contains two space-separated integers n and k (1≤n≤5⋅105; 0≤k≤105) — the length of the array a and the integer k.
The second line of each test case contains n space-separated integers a1,a2,…,an (1≤ai≤105) — representing the array a.
It is guaranteed that the sum of n over all test cases does not exceed 5⋅105.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤105),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含两个以空格分隔的整数 n 和 k(1≤n≤5⋅105;0≤k≤105),分别表示数组 a 的长度和整数 k。
每个测试用例的第二行包含 n 个以空格分隔的整数 a1,a2,…,an(1≤ai≤105),表示数组 a。
保证所有测试用例中 n 的总和不超过 5⋅105。
输出格式
For each test case, print the number of good pairs.
对于每个测试用例,输出好对的数量。
输入输出样例
输入#1
4 3 0 1 1 1 4 2 4 8 6 8 6 4 7 2 5 8 3 8 20 23 110 57 98 14 20 1 60 82 108 37 82 73 8 46 38 35 106 115 58 112
输出#1
6 9 18 92
说明/提示
In the first test case, good pairs are (1,1), (1,2), (1,3), (2,2), (2,3), and (3,3).
In the second test case, good pairs are (1,1), (1,3), (1,4), (2,2), (2,3), (2,4), (3,3), (3,4) and (4,4). Pair (1,4) is good because there exists a sequence of indices 1,3,4 which satisfy the given conditions.
在第一个测试用例中,好的数对为 (1,1)、(1,2)、(1,3)、(2,2)、(2,3) 和 (3,3)。
在第二个测试用例中,好的数对为 (1,1)、(1,3)、(1,4)、(2,2)、(2,3)、(2,4)、(3,3)、(3,4) 和 (4,4)。数对 (1,4) 是好的,因为存在一个下标序列 1,3,4 满足题目所给的条件。
输入解题思路,AI测评打分。不知道怎么写?