AtCoder Regular Contest++ 221
E
两个递增序列
Two Increasing Sequences
AtCoder
⌀ 3471
原题
← D→

两个递增序列AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

You are given a positive integer $N$, a positive integer $X$, and a permutation $P=(P_1,P_2,\ldots,P_N)$ of $(1,2,\ldots,N)$. Only $X$ is given in binary, while $N$ and the elements of $P$ are given in decimal.

给定一个正整数 $N$、一个正整数 $X$,以及一个由 $(1,2,\ldots,N)$ 构成的排列 $P=(P_1,P_2,\ldots,P_N)$。只有 $X$ 以二进制给出,$N$ 和 $P$ 的各个元素以十进制给出。AI (CI翻译)

Determine whether there exist sequences of non-negative integers $A=(A_1,A_2,\ldots,A_N)$ and $B=(B_1,B_2,\ldots,B_N)$ satisfying all of the following conditions.

判断是否存在两个非负整数序列 $A=(A_1,A_2,\ldots,A_N)$ 和 $B=(B_1,B_2,\ldots,B_N)$,满足以下所有条件:AI (CI翻译)

  • Both $A$ and $B$ are strictly increasing sequences.
  • $A_{P_i}=B_i \oplus X$ holds for $i=1,2,\ldots,N$.
  • $A$ 和 $B$ 都是严格递增序列。
  • 对于 $i=1,2,\ldots,N$,都有 $A_{P_i}=B_i \oplus X$。
AI (CI翻译)

Here, the binary operator $\oplus$ denotes the bitwise XOR of non-negative integers.

这里,二元运算符 $\oplus$ 表示非负整数的按位异或。AI (CI翻译)

You are given $T$ test cases; solve each of them.

给定 $T$ 组测试用例,请分别求解。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $1\le T\le 10^5$
  • $2\le N\le 2\times 10^5$
  • $1\le X < 2^{10^6}$
  • $P$ is a permutation of $(1,2,\ldots,N)$.
  • The sum of $N$ over all test cases is at most $2\times 10^5$.
  • The sum of the number of digits of $X$ in binary over all test cases is at most $10^6$.
  • $T,N,P_i$ are given in decimal.
  • $X$ is given in binary without leading zeros.
  • All input values are integers.
  • $1\le T\le 10^5$
  • $2\le N\le 2\times 10^5$
  • $1\le X < 2^{10^6}$
  • $P$ 是 $(1,2,\ldots,N)$ 的一个排列。
  • 所有测试用例中 $N$ 的总和至多为 $2\times 10^5$。
  • 所有测试用例中 $X$ 的二进制位数之和至多为 $10^6$。
  • $T,N,P_i$ 以十进制给出。
  • $X$ 以二进制给出,且不含前导零。
  • 所有输入值均为整数。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

The input is given from Standard Input in the following format:

输入从标准输入读入,格式如下:AI (CI翻译)

T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T

T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T
AI (CI翻译)

Each test case is given in the following format:

每组测试用例的格式如下:AI (CI翻译)

N
X
P_1 P_2 \ldots P_N

N
X
P_1 P_2 \ldots P_N
AI (CI翻译)

Output

输出格式

AI (CI翻译)

Output the answers for the test cases in order, separated by newlines.

按顺序输出各组测试用例的答案,每个答案占一行。AI (CI翻译)

For each test case, output Yes if there exist $A$ and $B$ satisfying all the conditions, and No otherwise.

对于每组测试用例,如果存在满足所有条件的 $A$ 和 $B$,输出 Yes;否则输出 No。AI (CI翻译)

样例

Input #1
3
4
101
3 4 2 1
4
100
4 3 2 1
8
1101011
3 5 4 1 2 6 8 7
Output #1
Yes
No
Yes
For the first test case, for example, $A=(2,3,5,7)$ and $B=(0,2,6,7)$ satisfy the conditions.
题目信息
题号
arc221_e
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。