「LAOI-4」Mex Tower (Hard ver.)

Luogu
IDLGP10370
Time500ms
Memory64MB
DifficultyP5
O2优化Ad-hoc洛谷比赛
定义 $\operatorname{mex}(x, y)$ 表示在集合 $\{x, y\}$ 中最小的未出现的 **自然数**。例如,$\operatorname{mex}(1, 5) = 0$,$\operatorname{mex}(3, 0) = 1$。 继而,我们定义对自然数序列 $a_1\dots a_n$ 的一次操作,是将序列 $a$ 替换为 **长度为 $\bm{n - 1}$ 的** 序列 $a'_1\dots a'_{n-1}$,其中 $a'_i = \operatorname{mex}(a_i, a_{i+1})$。 一个长度为 $n$ 的整数序列 $a_1\dots a_n$,满足 $0 \leq a_i \leq 10^9$;然后依次对它进行 $n - 1$ 次操作。显然最终序列 $a$ 只会剩下一个数,定义这最终一个数的值成为 **该序列的价值**,记为 $f(a)$。 请问对于给定的 $n$ 和 $a$ 序列,是否对于所有长度为 $n$ 的自然数序列 $b$,$f(a)\ge f(b)$。 ## Input **本题有多组数据。** 第一行一个正整数 $T$,表示数据组数。 对于每组数据,第一行一个正整数 $n$。 接下来 $n$ 个整数,表示序列 $a$。 ## Output 对于每组数据,一行一个字符串 `Yes` 或 `No`。 [samples] ## Background **本题与 Easy Version 的区别为本题需判断方案的合法性。** **保证本题所有的测试点时空限制均为 std 的 $2.5$ 倍及以上**。 ## Note ## 提示 ### 样例解释 对于 $n = 2$,$f(a)=2$。可以证明,对于所有长度为 $2$ 的 $b$ 序列满足 $f(b)\le 2$。 对于 $n = 3$,$f(a)=0$,存在序列 $b=[114,514,1919]$,$f(b)=1>0$。 ### 数据规模与约定 **「本题采用捆绑测试」** | $\text{Subtask}$ | $\sum n \le$| 特殊性质 | 总分值 | | :--------------: | :-----: |:-----: | :--------: | | $1$ | $10^3$ | 无| $10$ | $2$ | $5\cdot 10^5$ | $\text{A}$ | $5$ | | $3$ | $5\cdot 10^5$ | $\text{B}$ | $10$ | | $4$ | $5\cdot 10^5$ | $a_i< 2$ | $15$ | | $5$ | $10^6$ | 无 | $20$ | | $6$ | $3\cdot 10^6$ | 无 | $40$ | 特殊性质 $\text{A}$:保证 $a_i=i$。 特殊性质 $\text{B}$:保证 $a_i=i\bmod 3$。 对于所有数据,保证 $1 \leq T \leq 10^4$,$n > 1$,$\sum n \leq 3\cdot 10^6$。
Samples
Input #1
2
2
0 1
3
1 0 2
Output #1
Yes
No
API Response (JSON)
{
  "problem": {
    "name": "「LAOI-4」Mex Tower (Hard ver.)",
    "description": {
      "content": " 定义 $\\operatorname{mex}(x, y)$ 表示在集合 $\\{x, y\\}$ 中最小的未出现的 **自然数**。例如,$\\operatorname{mex}(1, 5) = 0$,$\\operatorname{mex}(3, 0) = 1$。 继而,我们定义对自然数序列 $a_1\\dots a_n$ 的一次操作,是将序列 $a$ 替换为 **长度为 $\\bm{n - 1}$ 的",
      "description_type": "Markdown"
    },
    "platform": "Luogu",
    "limit": {
      "time_limit": 500,
      "memory_limit": 65536
    },
    "difficulty": {
      "LuoguStyle": "P5"
    },
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "LGP10370"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "定义 $\\operatorname{mex}(x, y)$ 表示在集合 $\\{x, y\\}$ 中最小的未出现的 **自然数**。例如,$\\operatorname{mex}(1, 5) = 0$,$\\operatorname{mex}(3, 0) = 1$。\n\n继而,我们定义对自然数序列 $a_1\\dots a_n$ 的一次操作,是将序列 $a$ 替换为 **长度为 $\\bm{n - 1}$ 的*...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments