AT_arc221_e.Two Increasing Sequences

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given a positive integer NN, a positive integer XX, and a permutation P=(P1,P2,…,PN)P=(P_1,P_2,\ldots,P_N) of (1,2,…,N)(1,2,\ldots,N). Only XX is given in binary, while NN and the elements of PP are given in decimal.

Determine whether there exist sequences of non-negative integers A=(A1,A2,…,AN)A=(A_1,A_2,\ldots,A_N) and B=(B1,B2,…,BN)B=(B_1,B_2,\ldots,B_N) satisfying all of the following conditions.

  • Both AA and BB are strictly increasing sequences.
  • APi=Bi⊕XA_{P_i}=B_i \oplus X holds for i=1,2,…,Ni=1,2,\ldots,N.

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

You are given TT test cases; solve each of them.

给你一个正整数 NN、一个正整数 XX,以及 (1,2,…,N)(1,2,\ldots,N) 的一个排列 P=(P1,P2,…,PN)P=(P_1,P_2,\ldots,P_N)。其中仅 XX 以二进制形式给出,而 NN 和排列 PP 的各元素均以十进制形式给出。

请判断是否存在两个非负整数序列 A=(A1,A2,…,AN)A=(A_1,A_2,\ldots,A_N) 和 B=(B1,B2,…,BN)B=(B_1,B_2,\ldots,B_N),同时满足以下所有条件:

  • 序列 AA 和 BB 均为严格递增序列;
  • 对于 i=1,2,…,Ni=1,2,\ldots,N,均有 APi=Bi⊕XA_{P_i}=B_i \oplus X 成立。

此处,二元运算符 ⊕\oplus 表示非负整数的按位异或(bitwise XOR)。

你将得到 TT 组测试用例,请对每组分别求解。

输入格式

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

TT
case1\text{case}_1
case2\text{case}_2
⋮\vdots
caseT\text{case}_T

Each test case is given in the following format:

NN
XX
P1P_1 P2P_2 …\ldots PNP_N

输入从标准输入中按以下格式给出:

TT
case1\text{case}_1
case2\text{case}_2
⋮\vdots
caseT\text{case}_T

每个测试用例按以下格式给出:

NN
XX
P1P_1 P2P_2 …\ldots PNP_N

输出格式

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

For each test case, output Yes if there exist AA and BB satisfying all the conditions, and No otherwise.

按顺序输出各测试用例的答案,答案之间用换行符分隔。

对每个测试用例,若存在满足所有条件的 AA 和 BB,则输出 Yes;否则输出 No。

输入输出样例

  • 输入#1

    3
    4
    101
    3 4 2 1
    4
    100
    4 3 2 1
    8
    1101011
    3 5 4 1 2 6 8 7

    输出#1

    Yes
    No
    Yes

说明/提示

Sample 1 Explanation:
For the first test case, for example, A=(2,3,5,7)A=(2,3,5,7) and B=(0,2,6,7)B=(0,2,6,7) satisfy the conditions.

Constraints

  • 1≤T≤1051\le T\le 10^5
  • 2≤N≤2×1052\le N\le 2\times 10^5
  • 1≤X<21061\le X < 2^{10^6}
  • PP is a permutation of (1,2,…,N)(1,2,\ldots,N).
  • The sum of NN over all test cases is at most 2×1052\times 10^5.
  • The sum of the number of digits of XX in binary over all test cases is at most 10610^6.
  • T,N,PiT,N,P_i are given in decimal.
  • XX is given in binary without leading zeros.
  • All input values are integers.

样例 1 解释:
对于第一个测试用例,例如,A=(2,3,5,7)A=(2,3,5,7) 和 B=(0,2,6,7)B=(0,2,6,7) 满足条件。

约束条件

  • 1≤T≤1051\le T\le 10^5
  • 2≤N≤2×1052\le N\le 2\times 10^5
  • 1≤X<21061\le X < 2^{10^6}
  • PP 是 (1,2,…,N)(1,2,\ldots,N) 的一个排列。
  • 所有测试用例的 NN 之和不超过 2×1052\times 10^5。
  • 所有测试用例中 XX 的二进制表示的位数之和不超过 10610^6。
  • TT、NN、PiP_i 均以十进制给出。
  • XX 以二进制给出,且不含前导零。
  • 所有输入值均为整数。

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

首页