CF1671B.Consecutive Points Segment

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given nn points with integer coordinates on a coordinate axis OXOX. The coordinate of the ii-th point is xix_i. All points' coordinates are distinct and given in strictly increasing order.

For each point ii, you can do the following operation no more than once: take this point and move it by 11 to the left or to the right (i..e., you can change its coordinate xix_i to xi−1x_i - 1 or to xi+1x_i + 1). In other words, for each point, you choose (separately) its new coordinate. For the ii-th point, it can be either xi−1x_i - 1, xix_i or xi+1x_i + 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 ll the coordinates of points should be equal to l,l+1,…,l+n−1l, l + 1, \ldots, l + n - 1.

Note that the resulting points should have distinct coordinates.

You have to answer tt independent test cases.

给你 nn 个位于坐标轴 OXOX 上、具有整数坐标的点。第 ii 个点的坐标为 xix_i。所有点的坐标互不相同,且严格递增地给出。

对于每个点 ii,你最多可执行以下操作一次:将该点向左或向右移动 11 个单位(即,可将其坐标 xix_i 改为 xi−1x_i - 1 或 xi+1x_i + 1)。换言之,对每个点,你(独立地)选择其新坐标;对第 ii 个点,其新坐标可以是 xi−1x_i - 1、xix_i 或 xi+1x_i + 1 中的任意一个。

你的任务是判断:能否按上述方式移动某些点,使得新得到的点集构成一段连续的整数区间,即存在某个整数 ll,使得各点坐标恰好为 l,l+1,…,l+n−1l, l + 1, \ldots, l + n - 1。

注意:最终得到的点的坐标必须互不相同。

你需要回答 tt 个相互独立的测试用例。

输入格式

The first line of the input contains one integer tt (1≤t≤2⋅1041 \le t \le 2 \cdot 10^4) — the number of test cases. Then tt test cases follow.

The first line of the test case contains one integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the number of points in the set xx.

The second line of the test case contains nn integers x1<x2<…<xnx_1 \lt x_2 \lt \ldots \lt x_n (1≤xi≤1061 \le x_i \le 10^6), where xix_i is the coordinate of the ii-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 nn does not exceed 2⋅1052 \cdot 10^5 (∑n≤2⋅105\sum n \le 2 \cdot 10^5).

输入的第一行包含一个整数 tt(1≤t≤2⋅1041 \le t \le 2 \cdot 10^4),表示测试用例的数量。随后是 tt 个测试用例。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5),表示集合 xx 中点的个数。

每个测试用例的第二行包含 nn 个整数 x1<x2<…<xnx_1 \lt x_2 \lt \ldots \lt x_n(1≤xi≤1061 \le x_i \le 10^6),其中 xix_i 表示第 ii 个点的坐标。

保证所给点的坐标严格递增(这也意味着所有坐标互不相同)。同时保证所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5(即 ∑n≤2⋅105\sum n \le 2 \cdot 10^5)。

输出格式

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.

对于每个测试用例,输出答案:如果测试用例中的点集能够通过移动形成一个连续的整数区间,则输出 YES,否则输出 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

输入解题思路,AI测评打分。不知道怎么写?

首页