CF1851C.Tiles Comeback

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Vlad remembered that he had a series of nn tiles and a number kk. The tiles were numbered from left to right, and the ii-th tile had colour cic_i.

If you stand on the first tile and start jumping any number of tiles right, you can get a path of length pp. The length of the path is the number of tiles you stood on.

Vlad wants to see if it is possible to get a path of length pp such that:

  • it ends at tile with index nn;
  • pp is divisible by kk
  • the path is divided into blocks of length exactly kk each;
  • tiles in each block have the same colour, the colors in adjacent blocks are not necessarily different.

For example, let n=14n = 14, k=3k = 3.

The colours of the tiles are contained in the array cc = [1,2,1,1,7,5,3,3,1,3,4,4,2,4\color{red}{1}, \color{violet}{2}, \color{red}{1}, \color{red}{1}, \color{gray}{7}, \color{orange}{5}, \color{green}{3}, \color{green}{3}, \color{red}{1}, \color{green}{3}, \color{blue}{4}, \color{blue}{4}, \color{violet}{2}, \color{blue}{4}]. Then we can construct a path of length 66 consisting of 22 blocks:

c1→c3→c4→c11→c12→c14\color{red}{c_1} \rightarrow \color{red}{c_3} \rightarrow \color{red}{c_4} \rightarrow \color{blue}{c_{11}} \rightarrow \color{blue}{c_{12}} \rightarrow \color{blue}{c_{14}}

All tiles from the 11-st block will have colour 1\color{red}{\textbf{1}}, from the 22-nd block will have colour 4\color{blue}{\textbf{4}}.

It is also possible to construct a path of length 99 in this example, in which all tiles from the 11-st block will have colour 1\color{red}{\textbf{1}}, from the 22-nd block will have colour 3\color{green}{\textbf{3}}, and from the 33-rd block will have colour 4\color{blue}{\textbf{4}}.

弗拉德记得自己有一排 nn 块瓷砖和一个数 kk。瓷砖从左到右编号,第 ii 块瓷砖的颜色为 cic_i。

若你站在第一块瓷砖上,并向右跳跃任意数量的瓷砖,便可得到一条长度为 pp 的路径。路径的长度即为你所站过的瓷砖数量。

弗拉德想知道:是否存在一条长度为 pp 的路径,满足以下条件:

  • 路径终点为编号为 nn 的瓷砖;
  • pp 能被 kk 整除;
  • 该路径可被划分为若干个长度恰好为 kk 的连续块;
  • 每个块内的所有瓷砖颜色相同;相邻块的颜色可以相同,也可以不同。

例如,设 n=14n = 14,k=3k = 3。

瓷砖颜色数组 cc = [1,2,1,1,7,5,3,3,1,3,4,4,2,4\color{red}{1}, \color{violet}{2}, \color{red}{1}, \color{red}{1}, \color{gray}{7}, \color{orange}{5}, \color{green}{3}, \color{green}{3}, \color{red}{1}, \color{green}{3}, \color{blue}{4}, \color{blue}{4}, \color{violet}{2}, \color{blue}{4}]。那么我们可以构造一条长度为 66 的路径,包含 22 个块:

c1→c3→c4→c11→c12→c14\color{red}{c_1} \rightarrow \color{red}{c_3} \rightarrow \color{red}{c_4} \rightarrow \color{blue}{c_{11}} \rightarrow \color{blue}{c_{12}} \rightarrow \color{blue}{c_{14}}

其中,第 11 个块的所有瓷砖颜色均为 1\color{red}{\textbf{1}},第 22 个块的所有瓷砖颜色均为 4\color{blue}{\textbf{4}}。

在本例中,还可以构造一条长度为 99 的路径:第 11 个块的所有瓷砖颜色为 1\color{red}{\textbf{1}},第 22 个块的所有瓷砖颜色为 3\color{green}{\textbf{3}},第 33 个块的所有瓷砖颜色为 4\color{blue}{\textbf{4}}。

输入格式

The first line of input data contains a single 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 nn and kk (1≤k≤n≤2⋅1051 \le k \le n \le 2 \cdot 10^5)—the number of tiles in the series and the length of the block.

The second line of each test case contains nn integers c1,c2,c3,…,cnc_1, c_2, c_3, \dots, c_n (1≤ci≤n1 \le c_i \le n) — the colours of the tiles.

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 和 kk(1≤k≤n≤2⋅1051 \le k \le n \le 2 \cdot 10^5)——分别为瓷砖序列的长度和块的长度。

每个测试用例的第二行包含 nn 个整数 c1,c2,c3,…,cnc_1, c_2, c_3, \dots, c_n(1≤ci≤n1 \le c_i \le n)——表示各瓷砖的颜色。

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

输出格式

For each test case, output on a separate line:

  • YES if you can get a path that satisfies these conditions;
  • NO otherwise.

You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as positive response).

对于每个测试用例,在单独的一行上输出:

  • 如果可以得到一条满足这些条件的路径,则输出 YES;
  • 否则输出 NO。

YES 和 NO 的大小写不限(例如,字符串 yEs、yes、Yes 和 YES 均被视为肯定回答)。

输入输出样例

  • 输入#1

    10
    4 2
    1 1 1 1
    14 3
    1 2 1 1 7 5 3 3 1 3 4 4 2 4
    3 3
    3 1 3
    10 4
    1 2 1 2 1 2 1 2 1 2
    6 2
    1 3 4 1 6 6
    2 2
    1 1
    4 2
    2 1 1 1
    2 1
    1 2
    3 2
    2 2 2
    4 1
    1 1 2 2

    输出#1

    YES
    YES
    NO
    NO
    YES
    YES
    NO
    YES
    YES
    YES

说明/提示

In the first test case, you can jump from the first tile to the last tile;

The second test case is explained in the problem statement.

在第一个测试用例中,你可以从第一块瓷砖跳到最后一块瓷砖;

第二个测试用例已在题目描述中说明。

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

首页