309520: CF1692G. 2^Sort

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:3 Solved:0

Description

2^Sort

题意翻译

给你一个长度为 $n \ (\sum n < 2\cdot 10^5)$ 的数组 $a$,问你在这个数组中,有多少个长度为 $k + 1 \ (1\le k < n)$ 的区间,符合以下的条件: $$ 2^0 \cdot a_i < 2^1 \cdot a_{i + 1} < 2^2 \cdot a_{i + 2} < \dotsi < 2^k \cdot a_{i + k}\\ \footnotesize{注:i 为这个区间开始的位置} $$ 由[tzyt](https://www.luogu.com.cn/user/394488)翻译

题目描述

Given an array $ a $ of length $ n $ and an integer $ k $ , find the number of indices $ 1 \leq i \leq n - k $ such that the subarray $ [a_i, \dots, a_{i+k}] $ with length $ k+1 $ (not with length $ k $ ) has the following property: - If you multiply the first element by $ 2^0 $ , the second element by $ 2^1 $ , ..., and the ( $ k+1 $ )-st element by $ 2^k $ , then this subarray is sorted in strictly increasing order. More formally, count the number of indices $ 1 \leq i \leq n - k $ such that $ $2^0 \cdot a_i < 2^1 \cdot a_{i+1} < 2^2 \cdot a_{i+2} < \dots < 2^k \cdot a_{i+k}. $ $

输入输出格式

输入格式


The first line contains an integer $ t $ ( $ 1 \leq t \leq 1000 $ ) — the number of test cases. The first line of each test case contains two integers $ n $ , $ k $ ( $ 3 \leq n \leq 2 \cdot 10^5 $ , $ 1 \leq k < n $ ) — the length of the array and the number of inequalities. The second line of each test case contains $ n $ integers $ a_1, a_2, \dots, a_n $ ( $ 1 \leq a_i \leq 10^9 $ ) — the elements of the array. The sum of $ n $ across all test cases does not exceed $ 2 \cdot 10^5 $ .

输出格式


For each test case, output a single integer — the number of indices satisfying the condition in the statement.

输入输出样例

输入样例 #1

6
4 2
20 22 19 84
5 1
9 5 3 2 1
5 2
9 5 3 2 1
7 2
22 12 16 4 3 22 12
7 3
22 12 16 4 3 22 12
9 3
3 9 12 3 9 12 3 9 12

输出样例 #1

2
3
2
3
1
0

说明

In the first test case, both subarrays satisfy the condition: - $ i=1 $ : the subarray $ [a_1,a_2,a_3] = [20,22,19] $ , and $ 1 \cdot 20 < 2 \cdot 22 < 4 \cdot 19 $ . - $ i=2 $ : the subarray $ [a_2,a_3,a_4] = [22,19,84] $ , and $ 1 \cdot 22 < 2 \cdot 19 < 4 \cdot 84 $ . In the second test case, three subarrays satisfy the condition: - $ i=1 $ : the subarray $ [a_1,a_2] = [9,5] $ , and $ 1 \cdot 9 < 2 \cdot 5 $ . - $ i=2 $ : the subarray $ [a_2,a_3] = [5,3] $ , and $ 1 \cdot 5 < 2 \cdot 3 $ . - $ i=3 $ : the subarray $ [a_3,a_4] = [3,2] $ , and $ 1 \cdot 3 < 2 \cdot 2 $ . - $ i=4 $ : the subarray $ [a_4,a_5] = [2,1] $ , but $ 1 \cdot 2 = 2 \cdot 1 $ , so this subarray doesn't satisfy the condition.

Input

题意翻译

给你一个长度为 $n \ (\sum n < 2\cdot 10^5)$ 的数组 $a$,问你在这个数组中,有多少个长度为 $k + 1 \ (1\le k < n)$ 的区间,符合以下的条件: $$ 2^0 \cdot a_i < 2^1 \cdot a_{i + 1} < 2^2 \cdot a_{i + 2} < \dotsi < 2^k \cdot a_{i + k}\\ \footnotesize{注:i 为这个区间开始的位置} $$ 由[tzyt](https://www.luogu.com.cn/user/394488)翻译

Output

**题目大意**:

给定一个长度为 $ n $ 的数组 $ a $ 和一个整数 $ k $,要求找出满足以下条件的不同的起始索引 $ i $ 的数量:

- 从数组中的第 $ i $ 个元素开始,长度为 $ k+1 $ 的子数组 $ [a_i, a_{i+1}, \ldots, a_{i+k}] $ 在乘以 $ 2^0, 2^1, \ldots, 2^k $ 后,严格递增。

即对于每个 $ i $,满足 $ 2^0 \cdot a_i < 2^1 \cdot a_{i+1} < 2^2 \cdot a_{i+2} < \ldots < 2^k \cdot a_{i+k} $。

**输入输出数据格式**:

**输入格式**:
- 第一行包含一个整数 $ t $,表示测试用例的数量。
- 每个测试用例包含两行:
- 第一行包含两个整数 $ n $ 和 $ k $,分别表示数组长度和不等式的数量。
- 第二行包含 $ n $ 个整数 $ a_1, a_2, \ldots, a_n $,表示数组的元素。

**输出格式**:
- 对于每个测试用例,输出一个整数,表示满足条件的起始索引 $ i $ 的数量。

**输入输出样例**:

**输入样例**:
```
6
4 2
20 22 19 84
5 1
9 5 3 2 1
5 2
9 5 3 2 1
7 2
22 12 16 4 3 22 12
7 3
22 12 16 4 3 22 12
9 3
3 9 12 3 9 12 3 9 12
```

**输出样例**:
```
2
3
2
3
1
0
```

**说明**:

例如,在第一个测试用例中,有两个子数组满足条件:
- 当 $ i=1 $ 时,子数组 $ [20,22,19] $ 满足 $ 1 \cdot 20 < 2 \cdot 22 < 4 \cdot 19 $。
- 当 $ i=2 $ 时,子数组 $ [22,19,84] $ 满足 $ 1 \cdot 22 < 2 \cdot 19 < 4 \cdot 84 $。

在第二个测试用例中,有三个子数组满足条件:
- 当 $ i=1 $ 时,子数组 $ [9,5] $ 满足 $ 1 \cdot 9 < 2 \cdot 5 $。
- 当 $ i=2 $ 时,子数组 $ [5,3] $ 满足 $ 1 \cdot 5 < 2 \cdot 3 $。
- 当 $ i=3 $ 时,子数组 $ [3,2] $ 满足 $ 1 \cdot 3 < 2 \cdot 2 $。
- 当 $ i=4 $ 时,子数组 $ [2,1] $ 不满足条件,因为 $ 1 \cdot 2 = 2 \cdot 1 $。**题目大意**: 给定一个长度为 $ n $ 的数组 $ a $ 和一个整数 $ k $,要求找出满足以下条件的不同的起始索引 $ i $ 的数量: - 从数组中的第 $ i $ 个元素开始,长度为 $ k+1 $ 的子数组 $ [a_i, a_{i+1}, \ldots, a_{i+k}] $ 在乘以 $ 2^0, 2^1, \ldots, 2^k $ 后,严格递增。 即对于每个 $ i $,满足 $ 2^0 \cdot a_i < 2^1 \cdot a_{i+1} < 2^2 \cdot a_{i+2} < \ldots < 2^k \cdot a_{i+k} $。 **输入输出数据格式**: **输入格式**: - 第一行包含一个整数 $ t $,表示测试用例的数量。 - 每个测试用例包含两行: - 第一行包含两个整数 $ n $ 和 $ k $,分别表示数组长度和不等式的数量。 - 第二行包含 $ n $ 个整数 $ a_1, a_2, \ldots, a_n $,表示数组的元素。 **输出格式**: - 对于每个测试用例,输出一个整数,表示满足条件的起始索引 $ i $ 的数量。 **输入输出样例**: **输入样例**: ``` 6 4 2 20 22 19 84 5 1 9 5 3 2 1 5 2 9 5 3 2 1 7 2 22 12 16 4 3 22 12 7 3 22 12 16 4 3 22 12 9 3 3 9 12 3 9 12 3 9 12 ``` **输出样例**: ``` 2 3 2 3 1 0 ``` **说明**: 例如,在第一个测试用例中,有两个子数组满足条件: - 当 $ i=1 $ 时,子数组 $ [20,22,19] $ 满足 $ 1 \cdot 20 < 2 \cdot 22 < 4 \cdot 19 $。 - 当 $ i=2 $ 时,子数组 $ [22,19,84] $ 满足 $ 1 \cdot 22 < 2 \cdot 19 < 4 \cdot 84 $。 在第二个测试用例中,有三个子数组满足条件: - 当 $ i=1 $ 时,子数组 $ [9,5] $ 满足 $ 1 \cdot 9 < 2 \cdot 5 $。 - 当 $ i=2 $ 时,子数组 $ [5,3] $ 满足 $ 1 \cdot 5 < 2 \cdot 3 $。 - 当 $ i=3 $ 时,子数组 $ [3,2] $ 满足 $ 1 \cdot 3 < 2 \cdot 2 $。 - 当 $ i=4 $ 时,子数组 $ [2,1] $ 不满足条件,因为 $ 1 \cdot 2 = 2 \cdot 1 $。

加入题单

上一题 下一题 算法标签: