欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2000B.Seating in a Bus
Seating in a Bus
In Berland, a bus consists of a row of seats numbered from to . Passengers are advised to always board the bus following these rules:
- If there are no occupied seats in the bus, a passenger can sit in any free seat;
- Otherwise, a passenger should sit in any free seat that has at least one occupied neighboring seat. In other words, a passenger can sit in a seat with index () only if at least one of the seats with indices or is occupied.
Today, passengers boarded the bus. The array chronologically records the seat numbers they occupied. That is, contains the seat number where the first passenger sat, — the seat number where the second passenger sat, and so on.
You know the contents of the array . Determine whether all passengers followed the recommendations.
For example, if , and = [], then the recommendations were not followed, as the -rd passenger sat in seat number , while the neighboring seats with numbers and were free.
Input
The first line of input contains a single integer () — the number of test cases.
The following describes the input test cases.
The first line of each test case contains exactly one integer () — the number of seats in the bus and the number of passengers who boarded the bus.
The second line of each test case contains distinct integers () — the seats that the passengers occupied in chronological order.
It is guaranteed that the sum of values across all test cases does not exceed , and that no passenger sits in an already occupied seat.
Output
For each test case, output on a separate line:
- "
YES", if all passengers followed the recommendations; - "
NO" otherwise.
You may output the answer in any case (for example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as a positive answer).
Note
The first test case is explained in the problem statement.
Samples
4
5
5 4 2 1 3
3
2 3 1
4
2 3 1 4
5
1 2 3 5 4
NO
YES
YES
NO
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |