欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1851C.Tiles Comeback
Tiles Comeback
Vlad remembered that he had a series of tiles and a number . The tiles were numbered from left to right, and the -th tile had colour .
If you stand on the first tile and start jumping any number of tiles right, you can get a path of length . 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 such that:
- it ends at tile with index ;
- is divisible by
- the path is divided into blocks of length exactly each;
- tiles in each block have the same colour, the colors in adjacent blocks are not necessarily different.
For example, let , .
The colours of the tiles are contained in the array = [$\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 consisting of blocks:
$$\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 -st block will have colour , from the -nd block will have colour .
It is also possible to construct a path of length in this example, in which all tiles from the -st block will have colour , from the -nd block will have colour , and from the -rd block will have colour .
Input
The first line of input data contains a single integer () — the number of test cases.
The description of the test cases follows.
The first line of each test case contains two integers and ()—the number of tiles in the series and the length of the block.
The second line of each test case contains integers () — the colours of the tiles.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output on a separate line:
YESif you can get a path that satisfies these conditions;NOotherwise.
You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as positive response).
Note
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.
Samples
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
YES
YES
NO
NO
YES
YES
NO
YES
YES
YES
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |