欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2102B.The Picky Cat
The Picky Cat
You are given an array of integers . You are allowed to do the following operation any number of times (possibly zero):
- Choose an index (). Multiply by (i.e., update ).
Your task is to determine whether it is possible to make the element at index become the median of the array after doing the above operation any number of times. Note that operations can be applied to index as well, meaning the median can be either the original value of or its negation.
The median of an array is defined as the -th smallest element of array . For example, the median of the array is , while the median of the array is .
It is guaranteed that the absolute value of the elements of are distinct. Formally, there are no pairs of indices where .
is the ceiling function which returns the least integer greater than or equal to .
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 (, ) — the elements of the array .
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each testcase, output "YES" if it is possible to make the element at index become the median of the array, 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 test case, is already the median of the array , so no operation is required.
In the second test case, we can do two operations: one on index , and one on index . The array becomes , which has a median of .
In the third test case, if you do an operation on index , the array will become , which has a median of .
In the fourth test case, it can be proven that no sequence of operations can make the median of the array become or .
Samples
7
3
2 3 1
5
1 2 3 4 5
4
4 2 0 -5
4
-5 0 4 3
4
-10 8 3 2
1
1
10
9 1000 -999 -13 456 -223 23 24 10 0
YES
YES
YES
NO
NO
YES
YES
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |