CF1692G.2^Sort

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Given an array aa of length nn and an integer kk, find the number of indices 1≤i≤n−k1 \leq i \leq n - k such that the subarray [ai,…,ai+k][a_i, \dots, a_{i+k}] with length k+1k+1 (not with length kk) has the following property:

  • If you multiply the first element by 202^0, the second element by 212^1, ..., and the (k+1k+1)-st element by 2k2^k, then this subarray is sorted in strictly increasing order.

More formally, count the number of indices 1≤i≤n−k1 \leq i \leq n - k such that $$2^0 \cdot a_i \lt 2^1 \cdot a_{i+1} \lt 2^2 \cdot a_{i+2} \lt \dots \lt 2^k \cdot a_{i+k}.$$

给定一个长度为 nn 的数组 aa 和一个整数 kk,请找出满足以下条件的下标 1≤i≤n−k1 \leq i \leq n - k 的个数:

子数组 [ai,…,ai+k][a_i, \dots, a_{i+k}] 的长度为 k+1k+1(注意:不是 kk),且具有如下性质:

  • 若将第一个元素乘以 202^0,第二个元素乘以 212^1,……,第 (k+1)(k+1) 个元素乘以 2k2^k,则该子数组严格递增。

更形式化地说,需统计满足如下不等式的下标 1≤i≤n−k1 \leq i \leq n - k 的个数:

20⋅ai<21⋅ai+1<22⋅ai+2<⋯<2k⋅ai+k.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 tt (1≤t≤10001 \leq t \leq 1000) — the number of test cases.

The first line of each test case contains two integers nn, kk (3≤n≤2⋅1053 \leq n \leq 2 \cdot 10^5, 1≤k<n1 \leq k \lt n) — the length of the array and the number of inequalities.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1091 \leq a_i \leq 10^9) — the elements of the array.

The sum of nn across all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤10001 \leq t \leq 1000)—— 测试用例的数量。

每个测试用例的第一行包含两个整数 nn、kk(3≤n≤2⋅1053 \leq n \leq 2 \cdot 10^5,1≤k<n1 \leq k \lt n)—— 数组的长度和不等式的数量。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1091 \leq a_i \leq 10^9)—— 数组的元素。

所有测试用例中 nn 的总和不超过 2⋅1052 \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=1i=1: the subarray [a1,a2,a3]=[20,22,19][a_1,a_2,a_3] = [20,22,19], and 1⋅20<2⋅22<4⋅191 \cdot 20 \lt 2 \cdot 22 \lt 4 \cdot 19.
  • i=2i=2: the subarray [a2,a3,a4]=[22,19,84][a_2,a_3,a_4] = [22,19,84], and 1⋅22<2⋅19<4⋅841 \cdot 22 \lt 2 \cdot 19 \lt 4 \cdot 84.

In the second test case, three subarrays satisfy the condition:

  • i=1i=1: the subarray [a1,a2]=[9,5][a_1,a_2] = [9,5], and 1⋅9<2⋅51 \cdot 9 \lt 2 \cdot 5.
  • i=2i=2: the subarray [a2,a3]=[5,3][a_2,a_3] = [5,3], and 1⋅5<2⋅31 \cdot 5 \lt 2 \cdot 3.
  • i=3i=3: the subarray [a3,a4]=[3,2][a_3,a_4] = [3,2], and 1⋅3<2⋅21 \cdot 3 \lt 2 \cdot 2.
  • i=4i=4: the subarray [a4,a5]=[2,1][a_4,a_5] = [2,1], but 1⋅2=2⋅11 \cdot 2 = 2 \cdot 1, so this subarray doesn't satisfy the condition.

在第一个测试用例中,两个子数组均满足条件:

  • i=1i=1:子数组 [a1,a2,a3]=[20,22,19][a_1,a_2,a_3] = [20,22,19],且 1⋅20<2⋅22<4⋅191 \cdot 20 \lt 2 \cdot 22 \lt 4 \cdot 19。
  • i=2i=2:子数组 [a2,a3,a4]=[22,19,84][a_2,a_3,a_4] = [22,19,84],且 1⋅22<2⋅19<4⋅841 \cdot 22 \lt 2 \cdot 19 \lt 4 \cdot 84。

在第二个测试用例中,三个子数组满足条件:

  • i=1i=1:子数组 [a1,a2]=[9,5][a_1,a_2] = [9,5],且 1⋅9<2⋅51 \cdot 9 \lt 2 \cdot 5。
  • i=2i=2:子数组 [a2,a3]=[5,3][a_2,a_3] = [5,3],且 1⋅5<2⋅31 \cdot 5 \lt 2 \cdot 3。
  • i=3i=3:子数组 [a3,a4]=[3,2][a_3,a_4] = [3,2],且 1⋅3<2⋅21 \cdot 3 \lt 2 \cdot 2。
  • i=4i=4:子数组 [a4,a5]=[2,1][a_4,a_5] = [2,1],但 1⋅2=2⋅11 \cdot 2 = 2 \cdot 1,因此该子数组不满足条件。

输入解题思路,AI测评打分。不知道怎么写?

首页