CF2244C.Stepan and Permutation
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Stepan found a permutation p of length n. Of course, he decided to sort it. To make the process more interesting, he chose two positive integers x and y (x+y≤n) and defined a rule for swapping elements.
In one move, Stepan can choose two indices i and j (1≤i,j≤n) and swap the elements pi and pj if at least one of the following conditions holds:
- ∣i−j∣=x
- ∣i−j∣=y
Stepan wants to know whether it is possible to sort the permutation in ascending order using any number of such operations. Help him answer this question.
斯捷潘找到了一个长度为 n 的排列 p。当然,他决定将其排序。为了使过程更有趣,他选择了两个正整数 x 和 y(满足 x+y≤n),并定义了一条交换元素的规则。
在一次操作中,斯捷潘可以选择两个下标 i 和 j(1≤i,j≤n),当且仅当满足以下任一条件时,交换 pi 和 pj:
- ∣i−j∣=x
- ∣i−j∣=y
斯捷潘想知道:能否通过任意次数的此类操作,将该排列升序排序?请帮助他回答这个问题。
输入格式
The first line contains a single integer t (1≤t≤104) — the number of test cases.
The first line of each test case contains three integers n, x, and y (1≤x,y≤n≤2⋅105, x+y≤n) — the length of the array and the numbers chosen by Stepan.
The second line of each test case contains n integers pi (1≤pi≤n) — the array p; it is guaranteed that p is a permutation.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)——测试用例的数量。
每个测试用例的第一行包含三个整数 n、x 和 y(1≤x,y≤n≤2⋅105,且 x+y≤n)——数组的长度以及 Stepan 所选择的两个数。
每个测试用例的第二行包含 n 个整数 pi(1≤pi≤n)——数组 p;保证 p 是一个排列。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each test case, output "YES" if it is possible to sort the permutation with the given x and y, and "NO" otherwise.
You may output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted.
对于每个测试用例,如果能够使用给定的 x 和 y 对该排列进行排序,则输出 “YES”,否则输出 “NO”。
你可以以任意大小写形式输出每个字母(小写或大写)。例如,字符串 “yEs”、“yes”、“Yes” 和 “YES” 均可被接受。
输入输出样例
输入#1
4 5 2 3 5 4 3 2 1 6 2 4 2 1 4 3 6 5 4 2 2 1 2 3 4 5 2 3 1 2 3 5 4
输出#1
YES NO YES YES
说明/提示
null
输入解题思路,AI测评打分。不知道怎么写?