C - K Swap Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300300

問題文

長さ NN の数列 A=(a1,,aN)A=(a_1,\ldots,a_N) があります。また、整数 KK が与えられます。

あなたは次の操作を 00 回以上何度でも行えます。

  • 1iNK1 \leq i \leq N-K を満たす整数 ii を選び、aia_iai+Ka_{i+K} の値を入れ替える。

AA を昇順に並べ替えることが出来るかどうかを判定してください。

制約

  • 2N2×1052 \leq N \leq 2 \times 10^5
  • 1KN11 \leq K \leq N-1
  • 1ai1091 \leq a_i \leq 10^9
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

NN KK
a1a_1 \ldots aNa_N

出力

AA を昇順に並び替えることが出来るならば Yes と、出来ないならば No と出力せよ。


入力例 1Copy

Copy
5 2
3 4 1 3 4

出力例 1Copy

Copy
Yes

次のように操作をすることで AA を昇順に並び替えることが出来ます。

  • i=1i=1 とし、a1a_1a3a_3 の値を入れ替える。数列は (1,4,3,3,4)(1,4,3,3,4) となる。
  • i=2i=2 とし、a2a_2a4a_4 の値を入れ替える。数列は (1,3,3,4,4)(1,3,3,4,4) となる。

入力例 2Copy

Copy
5 3
3 4 1 3 4

出力例 2Copy

Copy
No

入力例 3Copy

Copy
7 5
1 2 3 4 5 5 10

出力例 3Copy

Copy
Yes

操作を行う必要が無い場合もあります。

Score : 300300 points

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 1Copy

Copy
5 2
3 4 1 3 4

Sample Output 1Copy

Copy
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 2Copy

Copy
5 3
3 4 1 3 4

Sample Output 2Copy

Copy
No

Sample Input 3Copy

Copy
7 5
1 2 3 4 5 5 10

Sample Output 3Copy

Copy
Yes

No operations may be needed.



2025-04-26 (Sat)
15:20:12 +00:00