欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2191B.MEX Reordering
MEX Reordering
You are given an integer array consisting of elements. Denote $f(l, r) = \operatorname{MEX}([a_l, a_{l + 1}, \ldots, a_r])$.
Determine if there is a way to reorder the array such that for every (), . In other words, for every split point , the of the prefix must be different from the of the suffix.
The minimum excluded (MEX) of a collection of integers is defined as the smallest non-negative integer which does not occur in the collection .
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains a single integer () — the length of the array.
The second line of each test case contains integers ().
Output
Output "YES" if you can reorder so that the condition from the statement is satisfied, and "NO" otherwise. You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
Note
In the first example, the initial ordering of already satisfies the condition. The only choice for is . Then $f(1, i) = f(1, 1) = \operatorname{MEX}([a_1]) = \operatorname{MEX}([1]) = 0$, and $f(i + 1, n) = f(2, 2) = \operatorname{MEX}([a_2]) = \operatorname{MEX}([0]) = 1$. Since , the condition is satisfied.
In the second example, it can be shown that there is no way to reorder to satisfy the condition. As an example, consider the order and . We have $f(1, i) = f(1, 2) = \operatorname{MEX}([a_1, a_2]) = \operatorname{MEX}([3, 0]) = 1$, and $f(i + 1, n) = f(3, 3) = \operatorname{MEX}([a_3]) = \operatorname{MEX}([0]) = 1$, hence , so the choice of reordering is invalid.
In the third example, we can reorder into . When , $f(1, i) = f(1, 4) = \operatorname{MEX}([a_1, a_2, a_3, a_4]) = \operatorname{MEX}([1, 6, 1, 0]) = 2$, $f(i + 1, n) = f(5, 6) = \operatorname{MEX}([a_5, a_6]) = \operatorname{MEX}([0, 5]) = 1$, so the condition is satisfied for this . It can be verified that the condition is also satisfied for all other .
Samples
3
2
1 0
3
0 3 0
6
1 0 5 0 6 1
YES
NO
YES
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |