CF BUDDY
← Problems·

1592B · Hemose Shopping

1200 · constructive algorithms, dsu, math

Problem: 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.

Hemose has an array of nn 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:

  • Choose indices ii and jj such that 1i,jn1 \le i, j \le n, and ijx\lvert i - j \rvert \geq x. Then, swap elements aia_i and aja_j.

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 00)?

Input Format: Each test contains multiple test cases. The first line contains the number of test cases tt (1t105)(1 \leq t \leq 10^5). Description of the test cases follows.

The first line of each test case contains two integers nn and xx (1xn105)(1 \leq x \leq n \leq 10^5).

The second line of each test case contains nn integers a1,a2,...,ana_1, a_2, ..., a_n (1ai109)(1 \leq a_i \leq 10^9).

It is guaranteed that the sum of nn over all test cases doesn't exceed 21052 \cdot 10^5.

Output Format: For each test case, you should output a single string.

If Samez can sort the array in non-decreasing order using the operation written above, output "YES" (without quotes). Otherwise, output "NO" (without quotes).

You can print each letter of "YES" and "NO" in any case (upper or lower).

Note: In the first test case, you can't do any operations.

In the second test case, the array is already sorted.

In the third test case, you can do the operations as follows:

  • [5,1,2,3,4][5,1,2,3,4], swap(a1,a3)swap(a_1,a_3)
  • [2,1,5,3,4][2,1,5,3,4], swap(a2,a5)swap(a_2,a_5)
  • [2,4,5,3,1][2,4,5,3,1], swap(a2,a4)swap(a_2,a_4)
  • [2,3,5,4,1][2,3,5,4,1], swap(a1,a5)swap(a_1,a_5)
  • [1,3,5,4,2][1,3,5,4,2], swap(a2,a5)swap(a_2,a_5)
  • [1,2,5,4,3][1,2,5,4,3], swap(a3,a5)swap(a_3,a_5)
  • [1,2,3,4,5][1,2,3,4,5]

(Here swap(ai,aj)swap(a_i, a_j) refers to swapping elements at positions ii, jj).

Sample Cases

Case 1

Input

4
3 3
3 2 1
4 3
1 2 3 4
5 2
5 1 2 3 4
5 4
1 2 3 4 4

Output

NO
YES
YES
YES

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback