#P9746. 「KDOI-06-S」合并序列

    ID: 10662 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP2023洛谷原创Special JudgeO2优化区间 DP位运算洛谷月赛

「KDOI-06-S」合并序列

Problem Description

Given a sequence of length nn, a1,a2,ana_1,a_2,\ldots a_n.

You may perform several (possibly 00) operations on this sequence. In each operation, you will:

  • Choose three positive integers i<j<ki<j<k such that aiajak=0a_i\oplus a_j\oplus a_k=0, and the value of kk does not exceed the current length of the sequence. Let s=aiai+1aks=a_i\oplus a_{i+1}\oplus \cdots\oplus a_k.
  • Then, delete aia_i to aka_k, and insert ss at the position where these ki+1k-i+1 numbers originally were. Note that the length of sequence aa will decrease by (ki)(k-i).

Determine whether it is possible to make the sequence aa contain only one number, that is, after all operations, the length of aa is 11. If it is possible, you also need to provide one valid operation plan.

Input Format

Read input from standard input.

This problem contains multiple test cases.

The first line contains a positive integer TT, indicating the number of test cases.

For each test case, the first line contains a positive integer nn, indicating the initial length of the sequence.

The second line contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n, indicating the value of each element in the initial sequence.

Output Format

For each test case:

  • If there exists a plan such that the sequence aa is reduced to only one number, output Huoyu on the first line.
    • Then, on the second line output a non-negative integer tt, indicating the number of operations. You need to ensure 0tn0\le t\le n.
    • Then output tt lines, each containing three positive integers i,j,ki,j,k, indicating the three numbers you choose in this operation. You need to ensure i<j<ki<j<k and that kk does not exceed the current length of the sequence.
  • Otherwise, output one line containing the string Shuiniao.
2
5
3 3 1 4 5
9
3 4 6 5 4 5 1 2 4
Huoyu
2
3 4 5
1 2 3
Huoyu
3
1 3 4
2 3 4
1 2 4

Hint

[Sample Explanation #1]

For the first test case:

  • In the first operation, a3a4a5=145=0a_3\oplus a_4\oplus a_5=1\oplus4\oplus5=0, and the sequence becomes [3,3,0][3,3,0] after the operation.
  • In the second operation, a1a2a3=330=0a_1\oplus a_2\oplus a_3=3\oplus3\oplus0=0, and the sequence becomes [0][0] after the operation.

Thus, after two operations, the sequence aa contains only one number.

For the second test case:

  • In the first operation, a1a3a4=365=0a_1\oplus a_3\oplus a_4=3\oplus6\oplus5=0, s=4s=4, and the sequence becomes [4,4,5,1,2,4][4,4,5,1,2,4] after the operation.
  • In the second operation, a2a3a4=451=0a_2\oplus a_3\oplus a_4=4\oplus5\oplus1=0, and the sequence becomes [4,0,2,4][4,0,2,4] after the operation.
  • In the third operation, a1a2a4=404=0a_1\oplus a_2\oplus a_4=4\oplus0\oplus4=0, s=2s=2, and the sequence becomes [2][2] after the operation.

Thus, after three operations, the sequence aa contains only one number.

[Sample #2]

See merge/merge2.in and merge/merge2.ans under the contestant directory.

This sample satisfies the constraints of test points 676\sim7.

[Sample #3]

See merge/merge3.in and merge/merge3.ans under the contestant directory.

This sample satisfies the constraints of test points 121312\sim13.

[Constraints]

For all testdata, it is guaranteed that: 1T201\leq T\leq20, 1n5001\leq n\leq500, 0ai<5120\leq a_i<512.

Test Point ID nn n\sum n\leq ai<a_i<
11 =1=1 2020 512512
22 =2=2 4040
33 =3=3 6060
44 =4=4 8080
55 =5=5 100100
676\sim7 40\leq40 800800
898\sim9 70\leq70 1 4001~400
101110\sim11 130\leq130 2 6002~600
121312\sim13 300\leq300 6 0006~000 128128
141514\sim15 500\leq500 3 0003~000 6464
161716\sim17 128128
182018\sim20 10 00010~000 512512

[Note]

\oplus denotes the bitwise XOR operation.

Please fully trust the constant factors and efficiency of the program.

Translated by ChatGPT 5