CF1819A Constructive Problem

题目描述

给定整数 $n$ 和一个非负整数序列 $a$。 对于非负整数序列 $c$,记 $\text{MEX}(c)$ 表示**不存在**于 $c$ 中的最小非负整数。 记初始时 $m=\text{MEX}(a)$。 你需要进行下列操作恰好一次: - 选择整数 $l,r,k(1\leq l\leq r\leq n;0\leq k)$,然后将 $a_l,a_{l+1},\cdots,a_r$ 的值均变为 $k$。 判断能否通过恰好一次上述操作使操作后的 $a$ 满足 $\text{MEX}(a)=m+1$。 能输出 `Yes`,不能输出 `No`。 每个测试点包含 $t$ 组数据。

输入格式

第一行输入一个整数 $t(1\leq t\leq5\times10^4)$ 表示数据组数,接下来对于每组数据: 第一行输入一个整数 $n(1\leq n,\sum n\leq2\times10^5)$。 接下来输入一行 $n$ 个整数 $a_1,a_2,\cdots,a_n(0\leq a_i\leq10^9)$。

输出格式

对于每组数据: 如果能通过一次操作满足要求,输出 `Yes`;否则输出 `No`。 实际评测时校验器对大小写不敏感。 ### 样例解释 对于第一组数据: - 初始 $m=0$。 你可以选择 $l=1,r=3,k=0$,此后 $a=[0,0,0],\text{MEX}(a)=1=m+1$。 因此可以通过一次操作达成要求,答案为 `Yes`。 对于第二组数据: - 初始 $m=1$。 你可以选择 $l=2,r=3,k=1$,此后 $a=[0,1,1,0],\text{MEX}(a)=2=m+1$。 因此可以通过一次操作达成要求,答案为 `Yes`。 可以证明,在第三组和第四组数据中,我们不能通过一次操作达成要求,因此这两组数据的答案为 `No`。

说明/提示

In the first test case, $ \operatorname{MEX}(a) = 0 $ . If you set all elements of $ a $ to $ 0 $ , then $ \operatorname{MEX} $ of the resulting array will be $ 1 $ , and thus will increase by one. In the second test case, $ \operatorname{MEX}(a) = 1 $ . If we assign a value of $ 1 $ to the elements of $ a $ on a subsegment from $ 2 $ to $ 3 $ , we get an array $ [0, 1, 1, 0] $ for which $ \operatorname{MEX} $ is $ 2 $ , 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 $ \operatorname{MEX}(a) $ increases by exactly one.