CF2244C.Stepan and Permutation

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Stepan found a permutation pp of length nn. Of course, he decided to sort it. To make the process more interesting, he chose two positive integers xx and yy (x+y≤n)(x + y \le n) and defined a rule for swapping elements.

In one move, Stepan can choose two indices ii and jj (1≤i,j≤n)(1 \le i, j \le n) and swap the elements pip_i and pjp_j if at least one of the following conditions holds:

  • ∣i−j∣=x|i - j| = x
  • ∣i−j∣=y|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.

斯捷潘找到了一个长度为 nn 的排列 pp。当然,他决定将其排序。为了使过程更有趣,他选择了两个正整数 xx 和 yy(满足 x+y≤nx + y \le n),并定义了一条交换元素的规则。

在一次操作中,斯捷潘可以选择两个下标 ii 和 jj(1≤i,j≤n1 \le i, j \le n),当且仅当满足以下任一条件时,交换 pip_i 和 pjp_j:

  • ∣i−j∣=x|i - j| = x
  • ∣i−j∣=y|i - j| = y

斯捷潘想知道:能否通过任意次数的此类操作,将该排列升序排序?请帮助他回答这个问题。

输入格式

The first line contains a single integer tt (1≤t≤104)(1 \le t \le 10^4) — the number of test cases.

The first line of each test case contains three integers nn, xx, and yy (1≤x,y≤n≤2⋅105(1 \le x, y \le n \le 2 \cdot 10^5, x+y≤n)x + y \le n) — the length of the array and the numbers chosen by Stepan.

The second line of each test case contains nn integers pip_i (1≤pi≤n)(1 \le p_i \le n) — the array pp; it is guaranteed that pp is a permutation.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)——测试用例的数量。

每个测试用例的第一行包含三个整数 nn、xx 和 yy(1≤x,y≤n≤2⋅1051 \le x, y \le n \le 2 \cdot 10^5,且 x+y≤nx + y \le n)——数组的长度以及 Stepan 所选择的两个数。

每个测试用例的第二行包含 nn 个整数 pip_i(1≤pi≤n1 \le p_i \le n)——数组 pp;保证 pp 是一个排列。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output "YES" if it is possible to sort the permutation with the given xx and yy, 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.

对于每个测试用例,如果能够使用给定的 xx 和 yy 对该排列进行排序,则输出 “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测评打分。不知道怎么写?

首页