CF1819A.Constructive Problem

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

As you know, any problem that does not require the use of complex data structures is considered constructive. You are offered to solve one of such problems.

You are given an array aa of nn non-negative integers. You are allowed to perform the following operation exactly once: choose some non-empty subsegment al,al+1,,ara_l, a_{l+1}, \ldots, a_r of the array aa and a non-negative integer kk , and assign value kk to all elements of the array on the chosen subsegment.

The task is to find out whether MEX(a)\operatorname{MEX}(a) can be increased by exactly one by performing such an operation. In other words, if before the operation MEX(a)=m\operatorname{MEX}(a) = m held, then after the operation it must hold that MEX(a)=m+1\operatorname{MEX}(a) = m + 1 .

Recall that MEX\operatorname{MEX} of a set of integers c1,c2,,ckc_1, c_2, \ldots, c_k is defined as the smallest non-negative integer xx which does not occur in the set cc .

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt ( 1t500001 \le t \le 50\,000 ) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn ( 1n2000001 \le n \le 200\,000 ) — the number of elements of array aa .

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n ( 0ai1090 \le a_i \le 10^9 ) — elements of array aa .

It is guaranteed that the sum nn over all test cases does not exceed 200000200\,000 .

输出格式

For each test case, print "Yes" if you can increase MEX(a)\operatorname{MEX}(a) by exactly one by performing the operation from the statement exactly once, otherwise print "No".

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.

输入输出样例

  • 输入#1

    4
    3
    1 2 1
    4
    0 2 2 0
    4
    3 2 0 2
    1
    0

    输出#1

    Yes
    Yes
    No
    No

说明/提示

In the first test case, MEX(a)=0\operatorname{MEX}(a) = 0 . If you set all elements of aa to 00 , then MEX\operatorname{MEX} of the resulting array will be 11 , and thus will increase by one.

In the second test case, MEX(a)=1\operatorname{MEX}(a) = 1 . If we assign a value of 11 to the elements of aa on a subsegment from 22 to 33 , we get an array [0,1,1,0][0, 1, 1, 0] for which MEX\operatorname{MEX} is 22 , and thus is increased by one compared to the original.

It can be shown that in the third and fourth test cases it is impossible to perform an operation so that the value of MEX(a)\operatorname{MEX}(a) increases by exactly one.

首页