QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 1024 MB 總分: 100 难度: [顯示] 可 Hack ✓

#17303. Night Sky

统计

In ancient times, the little monster Nexus committed many evils, so the Archmage sealed it in the night sky. To complete the seal, the Archmage cast a spell to rearrange the stars, causing the night sky to present a specific constellation.

It is said that this seal has remained to this day, and no one knows its original appearance.

Description

While reading ancient books, Little H discovered that the stars in the night sky can be abstracted as a sequence of non-negative integers. The star sequence in ancient times was $A = [a_1, \dots, a_n]$, while the currently observed sequence is $B = [b_1, \dots, b_m]$.

The ancient books also record two types of spells used by the Archmage to rearrange the stars. Specifically, for a star sequence with a current length of at least 2, the Archmage can cast one of the following two spells:

  1. Delete the two leftmost elements of the sequence and insert their XOR sum at the rightmost end.
  2. Delete the two rightmost elements of the sequence and insert their XOR sum at the leftmost end.

It can be observed that each time a spell is cast, the length of the star sequence decreases by exactly 1. Little H guesses that perhaps the Archmage only used these two spells and cast them exactly $n - m$ times to transform the initial sequence $A$ into the current sequence $B$. You need to help him determine if this is possible; if it is, you also need to find a specific sequence of spells.

Input

The input is read from the file night.in.

This problem contains multiple test cases.

The first line contains two non-negative integers $c$ and $t$, representing the test case ID and the number of test cases, respectively. $c = 0$ indicates that this test case is a sample.

Following this, each test case is provided. For each test case: The first line contains two positive integers $n, m$. The second line contains $n$ non-negative integers $a_1, \dots, a_n$. * The third line contains $m$ non-negative integers $b_1, \dots, b_m$.

Output

The output is written to the file night.out.

For each test case: The first line outputs a string Yes or No, indicating whether it is possible for the Archmage to have transformed sequence $A$ into sequence $B$ using only these two spells. If possible, the second line outputs $n - m$ positive integers from $\{1, 2\}$, representing the type of spell cast each time.

Correctly answering the first part above will earn partial points; please refer to the [Subtasks] section for specific scoring rules.

Constraints

For all test cases: $1 \le t \le 10^3$ $1 \le m \le n \le 250$ For all $1 \le i \le n$, $0 \le a_i < 2^{30}$ For all $1 \le i \le m$, $0 \le b_i < 2^{30}$

Test Case ID $n \le$ $m \le$ $T \le$ Special Property
1, 2 16 16 $10^3$
3 250 1 30 None
4 250 2 30 None
5, 6 250 250 30 A
7 $\sim$ 9 50 50 50 B
10, 11 250 250 30 B
12 $\sim$ 14 50 50 50 C
15, 16 250 250 30 C
17 $\sim$ 19 50 50 50 D
20, 21 250 250 30 D
22, 23 50 50 50 None
24, 25 250 250 30 None

A sequence $S = [s_1, \dots, s_k]$ is defined as odd if and only if $k \ge 3$, $s_1 = s_2 = s_3 = 1$, and for all $4 \le i \le k$, $2 \mid s_i$.

A cyclic shift of a sequence $S = [s_1, \dots, s_k]$ is defined as follows: for a positive integer $p$ ($1 \le p \le k$), the sequence $[s_p, s_{p+1}, \dots, s_k, s_1, \dots, s_{p-1}]$ is a cyclic shift of sequence $S$.

  • Special Property A: $3 \mid n$.
  • Special Property B: Sequences $A$ and $B$ are both odd.
  • Special Property C: Sequences $A$ and $B$ each have a cyclic shift that is odd.
  • Special Property D: $2m \ge n$.

Subtasks

This problem contains two sub-questions. For each test case: Sub-question 1: For each test case, correctly determining the feasibility earns 50% of the points for that test case. Sub-question 2: On this basis, if a valid sequence of spells is correctly provided for each test case where the answer is Yes, the remaining 50% of the points for that test case are earned.

Note: For test cases where the answer is Yes, regardless of whether the contestant attempts to provide a correct sequence of spells, they must output $n - m$ integers from $\{1, 2\}$ on the second line to satisfy the output format.

Note

A checker.cpp is provided in the problem directory to verify the feasibility of the spell sequence. Note: The provided checker.cpp only verifies the correctness of the spell sequence for test cases where the answer is Yes, and does not check the correctness of the feasibility judgment.

Contestants can use the following command in the problem directory to compile and obtain the executable:

g++ checker.cpp -o checker -std=gnu++14 -O2 -static

After compiling to obtain the executable, contestants can use the following command in the problem directory to test:

./checker <input_file> <output_file>

Where <input_file> and <output_file> represent the paths to the input and output files, respectively.

Note: The input file provided by the contestant must satisfy the input format and data range specified in the problem, and the output file must satisfy the specified output format; otherwise, the correctness of the verification result is not guaranteed, and unpredictable errors may occur.

Examples

Input 1

0 5
2 2
1 2
1 2
3 2
3 4 2
6 3
5 3
2 3 4 5 6
6 1
1
1 2 3 4 5 6
0
7 2
3 3 5 6 1 2 8
11 3

Output 1

Yes

Yes
2
Yes
1 1
No
Yes
2 1 2 1 1

Note 1

The sample contains five test cases. For the first test case, sequence $A$ is identical to sequence $B$, so no spells need to be cast. For the second test case, after casting the second type of spell once, the rightmost 4 and 2 of sequence $A$ are deleted, and $4 \oplus 2 = 6$ is inserted at the leftmost end, resulting in sequence $B$. For the third test case: After casting the first type of spell once, the leftmost 2 and 3 of sequence $A$ are deleted, and $2 \oplus 3 = 1$ is inserted at the rightmost end, resulting in sequence $[4, 5, 6, 1]$. After casting the first type of spell again, the leftmost 4 and 5 are deleted, and $4 \oplus 5 = 1$ is inserted at the rightmost end, resulting in sequence $B$. For the fourth test case, it can be proven that it is impossible to transform sequence $A$ into sequence $B$ using only these two types of spells.

Examples 2-5

See the files night/night2.in and night/night2.ans, night/night3.in and night/night3.ans, night/night4.in and night/night4.ans, and night/night5.in and night/night5.ans in the contestant directory.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1270EditorialOpen《夜空》解题报告Anonymous2026-03-14 17:53:28View

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.