K-Sort
Time limit1.5sMemory limit1024 MB
Given a permutation and K, decide whether swapping elements K positions apart (cyclically) can sort it into ascending order.
- Level
Medium4 of 10
- Topics
- Number theory, Array
- Solved
- No attempts yet
Problem
You are given a permutation of length . A permutation of length is a sequence in which every integer from to appears exactly once.
A positive integer is also given. You may perform the following operation as many times as you like.
- For any (), swap the values of and .
Determine whether can be sorted into ascending order using this operation. See the hint for the definition of .
Input
The first line contains the length and the positive integer , separated by a space. ()
The second line contains the elements , separated by spaces. Each integer from to appears exactly once.
Output
Print YES if can be sorted into ascending order by repeating the operation, otherwise print NO.
Hint
is the remainder operation. is the remainder when is divided by . For example, .