QOJ.ac

QOJ

حد الوقت: 1.0 s حد الذاكرة: 256 MB مجموع النقاط: 100

#6795. 每个人都喜欢玩游戏

الإحصائيات

有一天,Acesrc 和 Roundgod 正在玩一个名为“重要的蛋糕选择对”(Important Choice Pairs of Cakes,简称 ICPC)的有趣游戏。

在这个游戏中,有一个变量 $X$,初始时 $X = 0$。Acesrc 拥有 $N$ 对数字 $(x_i, y_i)$,Roundgod 拥有 $M$ 对数字 $(x'_i, y'_i)$。

首先,对于每一对 $(x_i, y_i)$,Acesrc 将选择 $x_i$ 或 $y_i$ 中的一个。假设他选择了 $k$,则 $X$ 将变为 $(X \oplus k)$($\oplus$ 表示按位异或运算)。

在 Acesrc 完成 $N$ 次操作后,Roundgod 将对他的 $M$ 对数字执行相同的操作。

他们从一开始就知道对方所有的数字对。Acesrc 希望最终的 $X$ 值尽可能大,而 Roundgod 希望它尽可能小。

Acesrc 和 Roundgod 都非常聪明,他们会选择最优策略。你能预测最终 $X$ 的值吗?

输入格式

输入包含多组测试数据。第一行包含一个整数 $T$ ($1 \le T \le 20$),表示测试数据的组数。对于每组测试数据:

第一行包含两个整数 $N$ 和 $M$ ($1 \le N, M \le 10000$)。

接下来 $N$ 行,每行包含两个整数 $x_i, y_i$ ($1 \le x_i, y_i \le 10^{18}$),表示 Acesrc 的数字对。

接下来 $M$ 行,每行包含两个整数 $x'_i, y'_i$ ($1 \le x'_i, y'_i \le 10^{18}$),表示 Roundgod 的数字对。

输出格式

对于每组测试数据,输出一行,包含一个整数,表示最终的答案。

样例

样例输入 1

2
1 1
6 3
4 1
2 2
1 3
4 6
5 4
2 2

样例输出 1

2
2

说明

在第一个样例中,如果 Acesrc 选择 6,Roundgod 将选择 4,结果为 2。 如果 Acesrc 选择 3,Roundgod 将选择 1,结果也为 2。 因此答案是 2。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#325EditorialOpen题解jiangly2025-12-14 07:06:05View

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.