CF1671B.Consecutive Points Segment
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given n points with integer coordinates on a coordinate axis OX . The coordinate of the i -th point is xi . All points' coordinates are distinct and given in strictly increasing order.
For each point i , you can do the following operation no more than once: take this point and move it by 1 to the left or to the right (i..e., you can change its coordinate xi to xi−1 or to xi+1 ). In other words, for each point, you choose (separately) its new coordinate. For the i -th point, it can be either xi−1 , xi or xi+1 .
Your task is to determine if you can move some points as described above in such a way that the new set of points forms a consecutive segment of integers, i. e. for some integer l the coordinates of points should be equal to l,l+1,…,l+n−1 .
Note that the resulting points should have distinct coordinates.
You have to answer t independent test cases.
输入格式
The first line of the input contains one integer t ( 1≤t≤2⋅104 ) — the number of test cases. Then t test cases follow.
The first line of the test case contains one integer n ( 1≤n≤2⋅105 ) — the number of points in the set x .
The second line of the test case contains n integers x1<x2<…<xn ( 1≤xi≤106 ), where xi is the coordinate of the i -th point.
It is guaranteed that the points are given in strictly increasing order (this also means that all coordinates are distinct). It is also guaranteed that the sum of n does not exceed 2⋅105 ( ∑n≤2⋅105 ).
输出格式
For each test case, print the answer — if the set of points from the test case can be moved to form a consecutive segment of integers, print YES, otherwise print NO.
输入输出样例
输入#1
5 2 1 4 3 1 2 3 4 1 2 3 7 1 1000000 3 2 5 6
输出#1
YES YES NO YES YES