QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100

#5521. 优秀的 XOR 问题

Statistics

对于一个整数数组 $[b_1, b_2, \dots, b_k]$,我们定义其权值为所有元素的异或和($\oplus$)。 这里 $\oplus$ 表示按位异或运算。例如,$13 \oplus 6 = 11$,因为在二进制下,$13 = 1101$,$6 = 0110$,所以它们的异或结果为 $1011 = 11$。例如,数组 $[13, 1, 4]$ 的权值为 $8$。

给定一个整数数组 $[a_1, a_2, \dots, a_n]$。我们希望将其划分为若干个(多于一个)连续的子数组,使得这些子数组的权值各不相同。请判断这是否可行。如果可行,请给出一种划分方案。

输入格式

第一行包含一个整数 $t$ ($1 \le t \le 10^4$) —— 测试用例的数量。接下来是各测试用例的描述。

每个测试用例的第一行包含一个整数 $n$ ($2 \le n \le 2 \cdot 10^5$) —— 数组的长度。

每个测试用例的第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($0 \le a_i < 2^{30}$) —— 数组的元素。

保证所有测试用例的 $n$ 之和不超过 $2 \cdot 10^5$。

输出格式

对于每个测试用例,如果不存在这样的划分,输出 NO。

否则,输出 YES。在下一行输出一个整数 $k$ ($2 \le k \le n$) —— 你将数组 $a$ 划分成的子数组个数。

在接下来的 $k$ 行中,每行输出两个整数 $l_i, r_i$ ($1 \le l_i \le r_i \le n$),表示第 $i$ 个子数组为 $[a_{l_i}, a_{l_i+1}, \dots, a_{r_i}]$。你可以以任意顺序输出这些子数组,但 $1$ 到 $n$ 的每个数字必须恰好出现在一个区间 $[l_i, r_i]$ 中。

输出 YES 和 NO 时不区分大小写(例如,yEs、yes、Yes 均被视为肯定回答)。

样例

样例输入 1

4
2
0 0
3
1 2 3
5
16 8 4 2 1
6
42 42 42 42 42 42

样例输出 1

NO
YES
3
1 1
2 2
3 3
YES
2
1 1
2 5
NO

说明

在第一个测试用例中,无法将 $[0, 0]$ 划分为至少两个权值不同的子数组。

在第二个测试用例中,可以将数组 $[1, 2, 3]$ 划分为 3 个子数组 $[1], [2], [3]$,其权值分别为 $1, 2, 3$。

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.