codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1692G.md (2218B)


      1 Source: https://codeforces.com/problemset/problem/1692/G
      2 
      3 G. 2^Sort
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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:
     22 
     23 * 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.
     24 
     25 More formally, count the number of indices $1 \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}.$$
     26 
     27 Input
     28 
     29 The first line contains an integer $t$ ($1 \leq t \leq 1000$) — the number of test cases.
     30 
     31 The first line of each test case contains two integers $n$, $k$ ($3 \leq n \leq 2 \cdot 10^5$, $1 \leq k \lt n$) — the length of the array and the number of inequalities.
     32 
     33 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.
     34 
     35 The sum of $n$ across all test cases does not exceed $2 \cdot 10^5$.
     36 
     37 Output
     38 
     39 For each test case, output a single integer — the number of indices satisfying the condition in the statement.
     40 
     41 Example
     42 
     43 Input
     44 
     45 ```
     46 6
     47 
     48 4 2
     49 
     50 20 22 19 84
     51 
     52 5 1
     53 
     54 9 5 3 2 1
     55 
     56 5 2
     57 
     58 9 5 3 2 1
     59 
     60 7 2
     61 
     62 22 12 16 4 3 22 12
     63 
     64 7 3
     65 
     66 22 12 16 4 3 22 12
     67 
     68 9 3
     69 
     70 3 9 12 3 9 12 3 9 12
     71 ```
     72 
     73 Output
     74 
     75 ```
     76 2
     77 3
     78 2
     79 3
     80 1
     81 0
     82 ```
     83 
     84 Note
     85 
     86 In the first test case, both subarrays satisfy the condition:
     87 
     88 * $i=1$: the subarray $[a_1,a_2,a_3] = [20,22,19]$, and $1 \cdot 20 \lt 2 \cdot 22 \lt 4 \cdot 19$.
     89 * $i=2$: the subarray $[a_2,a_3,a_4] = [22,19,84]$, and $1 \cdot 22 \lt 2 \cdot 19 \lt 4 \cdot 84$.
     90 
     91 In the second test case, three subarrays satisfy the condition:
     92 
     93 * $i=1$: the subarray $[a_1,a_2] = [9,5]$, and $1 \cdot 9 \lt 2 \cdot 5$.
     94 * $i=2$: the subarray $[a_2,a_3] = [5,3]$, and $1 \cdot 5 \lt 2 \cdot 3$.
     95 * $i=3$: the subarray $[a_3,a_4] = [3,2]$, and $1 \cdot 3 \lt 2 \cdot 2$.
     96 * $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.