codeforces-scrape

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

1592B.md (2262B)


      1 Source: https://codeforces.com/problemset/problem/1592/B
      2 
      3 B. Hemose Shopping
      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 Hemose was shopping with his friends Samez, AhmedZ, AshrafEzz, TheSawan and O_E in Germany. As you know, Hemose and his friends are problem solvers, so they are very clever. Therefore, they will go to all discount markets in Germany.
     22 
     23 Hemose has an array of $n$ integers. He wants Samez to sort the array in the non-decreasing order. Since it would be a too easy problem for Samez, Hemose allows Samez to use only the following operation:
     24 
     25 * Choose indices $i$ and $j$ such that $1 \le i, j \le n$, and $\lvert i - j \rvert \geq x$. Then, swap elements $a_i$ and $a_j$.
     26 
     27 Can you tell Samez if there's a way to sort the array in the non-decreasing order by using the operation written above some finite number of times (possibly $0$)?
     28 
     29 Input
     30 
     31 Each test contains multiple test cases. The first line contains the number of test cases $t$ $(1 \leq t \leq 10^5)$. Description of the test cases follows.
     32 
     33 The first line of each test case contains two integers $n$ and $x$ $(1 \leq x \leq n \leq 10^5)$.
     34 
     35 The second line of each test case contains $n$ integers $a_1, a_2, ..., a_n$ $(1 \leq a_i \leq 10^9)$.
     36 
     37 It is guaranteed that the sum of $n$ over all test cases doesn't exceed $2 \cdot 10^5$.
     38 
     39 Output
     40 
     41 For each test case, you should output a single string.
     42 
     43 If Samez can sort the array in non-decreasing order using the operation written above, output "YES" (without quotes). Otherwise, output "NO" (without quotes).
     44 
     45 You can print each letter of "YES" and "NO" in any case (upper or lower).
     46 
     47 Example
     48 
     49 Input
     50 
     51 ```
     52 4
     53 3 3
     54 3 2 1
     55 4 3
     56 1 2 3 4
     57 5 2
     58 5 1 2 3 4
     59 5 4
     60 1 2 3 4 4
     61 ```
     62 
     63 Output
     64 
     65 ```
     66 NO
     67 YES
     68 YES
     69 YES
     70 ```
     71 
     72 Note
     73 
     74 In the first test case, you can't do any operations.
     75 
     76 In the second test case, the array is already sorted.
     77 
     78 In the third test case, you can do the operations as follows:
     79 
     80 * $[5,1,2,3,4]$, $swap(a_1,a_3)$
     81 * $[2,1,5,3,4]$, $swap(a_2,a_5)$
     82 * $[2,4,5,3,1]$, $swap(a_2,a_4)$
     83 * $[2,3,5,4,1]$, $swap(a_1,a_5)$
     84 * $[1,3,5,4,2]$, $swap(a_2,a_5)$
     85 * $[1,2,5,4,3]$, $swap(a_3,a_5)$
     86 * $[1,2,3,4,5]$
     87 
     88 (Here $swap(a_i, a_j)$ refers to swapping elements at positions $i$, $j$).