#abc254c. C - K Swap

C - K Swap

Score : 300300 points

问题描述

我们有一个长度为 NN 的序列:A=(a1,,aN)A=(a_1,\ldots,a_N)。另外,还给你一个整数 KK

你可以执行零次或多次以下操作。

  • 选择一个整数 ii,满足 1iNK1 \leq i \leq N-K,然后交换 aia_iai+Ka_{i+K} 的值。

确定是否可以将序列 AA 按升序排序。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

We have a sequence of length NN: A=(a1,,aN)A=(a_1,\ldots,a_N). Additionally, you are given an integer KK.

You can perform the following operation zero or more times.

  • Choose an integer ii such that 1iNK1 \leq i \leq N-K, then swap the values of aia_i and ai+Ka_{i+K}.

Determine whether it is possible to sort AA in ascending order.

Constraints

  • 2N2×1052 \leq N \leq 2 \times 10^5
  • 1KN11 \leq K \leq N-1
  • 1ai1091 \leq a_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN KK

a1a_1 \ldots aNa_N

Output

If it is possible to sort AA in ascending order, print Yes; otherwise, print No.

Sample Input 1

5 2
3 4 1 3 4

Sample Output 1

Yes

The following sequence of operations sorts AA in ascending order.

  • Choose i=1i=1 to swap the values of a1a_1 and a3a_3. AA is now (1,4,3,3,4)(1,4,3,3,4).
  • Choose i=2i=2 to swap the values of a2a_2 and a4a_4. AA is now (1,3,3,4,4)(1,3,3,4,4).

Sample Input 2

5 3
3 4 1 3 4

Sample Output 2

No

Sample Input 3

7 5
1 2 3 4 5 5 10

Sample Output 3

Yes

No operations may be needed.

update @ 2024/3/10 10:49:28