欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1669C.Odd/Even Increments
Odd/Even Increments
Given an array of positive integers, you can do operations of two types on it:
- Add to every element with an odd index. In other words change the array as follows: .
- Add to every element with an even index. In other words change the array as follows: .
Determine if after any number of operations it is possible to make the final array contain only even numbers or only odd numbers. In other words, determine if you can make all elements of the array have the same parity after any number of operations.
Note that you can do operations of both types any number of times (even none). Operations of different types can be performed a different number of times.
Input
The first line contains an integer () — the number of test cases.
The first line of each test case contains an integer () — the length of the array.
The second line of each test case contains integers () — the elements of the array.
Note that after the performed operations the elements in the array can become greater than .
Output
Output lines, each of which contains the answer to the corresponding test case. As an answer, output "YES" if after any number of operations it is possible to make the final array contain only even numbers or only odd numbers, and "NO" otherwise.
You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
Note
For the first test case, we can increment the elements with an even index, obtaining the array , which contains only odd numbers, so the answer is "YES".
For the second test case, we can show that after performing any number of operations we won't be able to make all elements have the same parity, so the answer is "NO".
For the third test case, all elements already have the same parity so the answer is "YES".
For the fourth test case, we can perform one operation and increase all elements at odd positions by , thus obtaining the array , and all elements become odd so the answer is "YES".
Samples
4
3
1 2 1
4
2 2 2 3
4
2 2 2 2
5
1000 1 1000 1 1000
YES
NO
YES
YES
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |