欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2163A.Souvlaki VS. Kalamaki
Souvlaki VS. Kalamaki
Two players, Souvlaki and Kalamaki, are given a sequence of integers.
They will play a game that consists of rounds, which are numbered from to . Souvlaki plays on odd-numbered rounds, and Kalamaki on even-numbered rounds.
On the -th round, a player can choose to take exactly one of the following actions:
- Skip his turn and proceed to round (or finish the game if round was the last one).
- Swap elements and .
Souvlaki wins if after the end of the last round, is sorted in non-decreasing order. In other words, he wins if holds for every . Otherwise, Kalamaki wins.
However, Souvlaki does not like losing, so before the start of the game, he may re-order the elements of in anyway he wants. Is it possible for him to do so such that he has a guaranteed winning strategy?
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 number of integers in .
The second line contains exactly integers () — where represents the -th element of .
Output
For each test case, output on a separate line "'YES"' if it is possible for Souvlaki to re-order the elements of such that he has a guaranteed winning strategy, 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, . A possible way to re-order the elements so that Souvlaki can win is the following: . Then, the game might go as follows:
- On round , it is Souvlaki's turn. He will choose to swap with , and now .
- On round , it is Kalamaki's turn. Whether he chooses to skip his turn or swap elements and , will remain the same. Suppose he skips his turn.
- On round , it is Souvlaki's turn. He can choose to skip his turn as well, because if he swapped the last two elements he would lose.
After every round, , sorted in non-decreasing order, so Souvlaki wins, no matter how Kalamaki chooses to play.
On the second example, since every element is equal, Souvlaki will always win because is always sorted in non-decreasing order.
Samples
5
4
4 2 2 1
4
1 1 1 1
5
1 5 1 5 1
3
1 2 3
5
1 3 2 3 5
YES
YES
YES
NO
NO
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |