QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 512 MB 満点: 100 ハック可能 ✓

#1899. 最大化异或和

統計

我们使用 $\oplus$ 作为整数按位“异或”运算的符号。在 C++ 和 Java 中,该运算由字符 ^ 表示;在 Pascal 和 Python 中,由关键字 xor 表示。例如,$9 \oplus 3 = 1001_2 \oplus 11_2 = 1010_2 = 10$。

给定两个长度为 $n$ 的整数数组 $A$ 和 $B$。记 $X(A)$ 为数组所有元素的按位“异或”和:$X(A) = A_1 \oplus A_2 \oplus \dots \oplus A_n$。同理,记 $X(B) = B_1 \oplus B_2 \oplus \dots \oplus B_n$。

对于每个 $i$($1 \le i \le n$),允许交换 $A_i$ 和 $B_i$。你需要找出应该交换哪些元素,使得 $X(A) + X(B)$ 的值最大。

输入格式

第一行包含一个整数 $n$ —— 数组的大小($1 \le n \le 10^5$)。下一行包含 $n$ 个整数 $A_i$ —— 数组 $A$ 的元素($0 \le A_i \le 10^{18}$)。下一行以相同格式包含数组 $B$。

输出格式

第一行输出必须包含 $X(A) + X(B)$ 的最大可能值以及一个整数 $k$ —— 所需交换的次数。下一行包含 $k$ 个不同的整数,范围在 $1$ 到 $n$ 之间,表示需要交换的元素的下标。

样例

输入 1

2
1 1
2 2

输出 1

6 1
1

说明

在样例中,交换后数组变为 $A = [2, 1]$ 和 $B = [1, 2]$。 $X(A) = 2 \oplus 1 = 10_2 \oplus 1_2 = 11_2 = 3$,$X(B) = 3$,$X(A) + X(B) = 6$。

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.