#DSU0000039. Stepan và hoán vị (Stepan and Permutation)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Stepan và hoán vị (Stepan and Permutation)
Stepan and Permutation
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a permutation of length and two positive integers satisfying . Your goal is to sort the permutation into .
In one operation, choose two positions and swap their current values if the distance between their indices equals or , that is, or . The distance concerns position indices, not the difference between stored values. Any number of operations may be performed, including repeated swaps of the same pair.
Determine whether a sequence of allowed operations can sort the initial permutation in increasing order.
Input
The first line contains ; the second contains permutation .
Output
Print YES or NO.
Subtasks
- Subtask 1 (20 points): ; , ; is a permutation of .
- Subtask 2 (30 points): ; , ; is a permutation of .
- Subtask 3 (50 points): ; , ; is a permutation of .
Examples
Input
5 2 3
5 4 3 2 1
Output
YES
Explanation
For , the permitted index differences are and . Position can be swapped with positions or , and those positions connect it to the remaining indices. Thus all values can be moved to the required positions, making the identity permutation reachable. The result is YES.