CF1592B.Hemose Shopping
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Hemose was shopping with his friends Samez, AhmedZ, AshrafEzz, TheSawan and O_E in Germany. As you know, Hemose and his friends are problem solvers, so they are very clever. Therefore, they will go to all discount markets in Germany.
Hemose has an array of n integers. He wants Samez to sort the array in the non-decreasing order. Since it would be a too easy problem for Samez, Hemose allows Samez to use only the following operation:
- Choose indices i and j such that 1≤i,j≤n, and ∣i−j∣≥x. Then, swap elements ai and aj.
Can you tell Samez if there's a way to sort the array in the non-decreasing order by using the operation written above some finite number of times (possibly 0)?
赫莫塞(Hemose)与他的朋友萨梅兹(Samez)、艾哈迈德Z(AhmedZ)、阿什拉夫·埃兹(AshrafEzz)、赛万(TheSawan)和O_E 一起在德国购物。众所周知,赫莫塞和他的朋友们都是解题高手,因此他们将逛遍德国所有的折扣市场。
赫莫塞有一个长度为 n 的整数数组。他希望萨梅兹将该数组按非递减顺序排序。但这个问题对萨梅兹来说过于简单,因此赫莫塞只允许萨梅兹使用以下操作:
- 选择下标 i 和 j,满足 1≤i,j≤n 且 ∣i−j∣≥x;然后交换元素 ai 和 aj。
你能告诉萨梅兹:是否存在一种方式,通过有限次(可能为 0 次)执行上述操作,将该数组排序为非递减顺序?
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤105). Description of the test cases follows.
The first line of each test case contains two integers n and x (1≤x≤n≤105).
The second line of each test case contains n integers a1,a2,...,an (1≤ai≤109).
It is guaranteed that the sum of n over all test cases doesn't exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t (1≤t≤105)。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 x (1≤x≤n≤105)。
每个测试用例的第二行包含 n 个整数 a1,a2,...,an (1≤ai≤109)。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each test case, you should output a single string.
If Samez can sort the array in non-decreasing order using the operation written above, output "YES" (without quotes). Otherwise, output "NO" (without quotes).
You can print each letter of "YES" and "NO" in any case (upper or lower).
对于每个测试用例,你应该输出一个字符串。
如果 Samez 能够使用上述操作将数组排序为非递减顺序,则输出 "YES"(不带引号);否则,输出 "NO"(不带引号)。
你可以以任意大小写(大写或小写)输出 "YES" 和 "NO" 中的每个字母。
输入输出样例
输入#1
4 3 3 3 2 1 4 3 1 2 3 4 5 2 5 1 2 3 4 5 4 1 2 3 4 4
输出#1
NO YES YES YES
说明/提示
In the first test case, you can't do any operations.
In the second test case, the array is already sorted.
In the third test case, you can do the operations as follows:
- [5,1,2,3,4], swap(a1,a3)
- [2,1,5,3,4], swap(a2,a5)
- [2,4,5,3,1], swap(a2,a4)
- [2,3,5,4,1], swap(a1,a5)
- [1,3,5,4,2], swap(a2,a5)
- [1,2,5,4,3], swap(a3,a5)
- [1,2,3,4,5]
(Here swap(ai,aj) refers to swapping elements at positions i, j).
在第一个测试用例中,你无法执行任何操作。
在第二个测试用例中,数组已经排好序。
在第三个测试用例中,你可以按如下方式执行操作:
- [5,1,2,3,4],执行 swap(a1,a3)
- [2,1,5,3,4],执行 swap(a2,a5)
- [2,4,5,3,1],执行 swap(a2,a4)
- [2,3,5,4,1],执行 swap(a1,a5)
- [1,3,5,4,2],执行 swap(a2,a5)
- [1,2,5,4,3],执行 swap(a3,a5)
- [1,2,3,4,5]
(此处 swap(ai,aj) 表示交换位置 i 与 j 处的元素)
输入解题思路,AI测评打分。不知道怎么写?