CF1893A.Anonymous Informant

普及/提高-

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are given an array b1,b2,…,bnb_1, b_2, \ldots, b_n.

An anonymous informant has told you that the array bb was obtained as follows: initially, there existed an array a1,a2,…,ana_1, a_2, \ldots, a_n, after which the following two-component operation was performed kk times:

  1. A fixed point†^{\dagger} xx of the array aa was chosen.
  2. Then, the array aa was cyclically shifted to the left‡^{\ddagger} exactly xx times.

As a result of kk such operations, the array b1,b2,…,bnb_1, b_2, \ldots, b_n was obtained. You want to check if the words of the anonymous informant can be true or if they are guaranteed to be false.

†^{\dagger}A number xx is called a fixed point of the array a1,a2,…,ana_1, a_2, \ldots, a_n if 1≤x≤n1 \leq x \leq n and ax=xa_x = x.

‡^{\ddagger}A cyclic left shift of the array a1,a2,…,ana_1, a_2, \ldots, a_n is the array a2,…,an,a1a_2, \ldots, a_n, a_1.

给你一个数组 b1,b2,…,bnb_1, b_2, \ldots, b_n。

一位匿名线人告诉你:数组 bb 是通过如下方式得到的:最初存在一个数组 a1,a2,…,ana_1, a_2, \ldots, a_n,然后对该数组重复执行以下两步操作共 kk 次:

  1. 选择数组 aa 的一个不动点†^{\dagger} xx;
  2. 接着将数组 aa 向左循环移位‡^{\ddagger} 恰好 xx 次。

经过 kk 次这样的操作后,得到了数组 b1,b2,…,bnb_1, b_2, \ldots, b_n。你想判断这位匿名线人的话是否可能为真,还是必然为假。

†^{\dagger} 若满足 1≤x≤n1 \leq x \leq n 且 ax=xa_x = x,则称数 xx 为数组 a1,a2,…,ana_1, a_2, \ldots, a_n 的一个不动点。

‡^{\ddagger} 数组 a1,a2,…,ana_1, a_2, \ldots, a_n 的向左循环移位是指数组 a2,…,an,a1a_2, \ldots, a_n, a_1。

输入格式

Each test contains multiple test cases. The first line contains an integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers n,kn, k (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5, 1≤k≤1091 \le k \le 10^9) — the length of the array bb and the number of operations performed.

The second line of each test case contains nn integers b1,b2,…,bnb_1, b_2, \ldots, b_n (1≤bi≤1091 \le b_i \le 10^9) — the elements of the array bb.

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

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 n,kn, k(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5,1≤k≤1091 \le k \le 10^9),分别表示数组 bb 的长度以及执行的操作次数。

每个测试用例的第二行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \ldots, b_n(1≤bi≤1091 \le b_i \le 10^9),表示数组 bb 的元素。

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

输出格式

For each test case, output "Yes" if the words of the anonymous informant can be true, and "No" if they are guaranteed to be false.

对于每个测试用例,如果匿名线人的陈述可能为真,则输出“Yes”;如果其陈述必然为假,则输出“No”。

输入输出样例

  • 输入#1

    6
    5 3
    4 3 3 2 3
    3 100
    7 2 1
    5 5
    6 1 1 1 1
    1 1000000000
    1
    8 48
    9 10 11 12 13 14 15 8
    2 1
    1 42

    输出#1

    Yes
    Yes
    No
    Yes
    Yes
    No

说明/提示

In the first test case, the array aa could be equal to [3,2,3,4,3][3, 2, 3, 4, 3]. In the first operation, a fixed point x=2x = 2 was chosen, and after 22 left shifts, the array became [3,4,3,3,2][3, 4, 3, 3, 2]. In the second operation, a fixed point x=3x = 3 was chosen, and after 33 left shifts, the array became [3,2,3,4,3][3, 2, 3, 4, 3]. In the third operation, a fixed point x=3x = 3 was chosen again, and after 33 left shifts, the array became [4,3,3,2,3][4, 3, 3, 2, 3], which is equal to the array bb.

In the second test case, the array aa could be equal to [7,2,1][7, 2, 1]. After the operation with a fixed point x=2x = 2, the array became [1,7,2][1, 7, 2]. Then, after the operation with a fixed point x=1x = 1, the array returned to its initial state [7,2,1][7, 2, 1]. These same 22 operations (with x=2x = 2, and x=1x = 1) were repeated 4949 times. So, after 100100 operations, the array returned to [7,2,1][7, 2, 1].

In the third test case, it can be shown that there is no solution.

在第一个测试用例中,数组 aa 可能等于 [3,2,3,4,3][3, 2, 3, 4, 3]。在第一次操作中,选择固定点 x=2x = 2,经过 22 次左移后,数组变为 [3,4,3,3,2][3, 4, 3, 3, 2]。在第二次操作中,选择固定点 x=3x = 3,经过 33 次左移后,数组变为 [3,2,3,4,3][3, 2, 3, 4, 3]。在第三次操作中,再次选择固定点 x=3x = 3,经过 33 次左移后,数组变为 [4,3,3,2,3][4, 3, 3, 2, 3],该结果与数组 bb 相等。

在第二个测试用例中,数组 aa 可能等于 [7,2,1][7, 2, 1]。在固定点 x=2x = 2 的操作之后,数组变为 [1,7,2][1, 7, 2];接着,在固定点 x=1x = 1 的操作之后,数组恢复为初始状态 [7,2,1][7, 2, 1]。上述相同的 22 次操作(即分别取 x=2x = 2 和 x=1x = 1)被重复执行了 4949 轮。因此,在总共 100100 次操作之后,数组最终回到 [7,2,1][7, 2, 1]。

在第三个测试用例中,可以证明不存在满足条件的解。

输入解题思路,AI测评打分。不知道怎么写?

首页