QOJ.ac

QOJ

Time Limit: 2.0 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#17149. XOR Раскраска

الإحصائيات

给定两个非负整数数组 $A=[a_1,a_2,\dots,a_n]$ 和 $B=[b_1,b_2,\dots,b_m]$。

定义 $S(i)=\{\,j \mid (a_i \oplus b_j)\le x\,\}$。换句话说,$S(i)$ 是数组 $B$ 中所有满足 $a_i$ 与 $b_j$ 的按位异或不超过 $x$ 的下标 $j$ 的集合。

要求找到最小的整数 $k$,使得可以将数组 $A$ 的元素染成 $k$ 种颜色,并且满足:如果 $S(x)$ 与 $S(y)$ 有交集,那么 $x$ 和 $y$ 必须被染成不同的颜色。

也就是说,需要找到颜色 $c_1,c_2,\dots,c_n$,满足 $1\le c_i\le k$,并且如果 $S(x)\cap S(y)\ne\varnothing$,则 $c_x\ne c_y$。

回顾一下,两个非负整数的按位“异或”($\oplus$,xor)定义如下:将两个数写成二进制表示,结果的第 $i$ 个二进制位为 1,当且仅当两个操作数中恰好有一个在该位为 1。例如:$(14\ \text{xor}\ 7)=(1110_2 \oplus 0111_2)=1001_2=9$。该运算在所有现代编程语言中都已实现,在 C++、Java 和 Python 中写作 ^,在 Pascal 中写作 xor

输入格式

本题输入包含多个测试用例。第一行包含一个整数 $t$ ($1\le t\le 100$) —— 测试用例的数量。

接下来是测试用例的描述。每个测试用例的第一行包含三个整数 $n,m,x$ ($1\le n,m\le 500\,000,\ 0\le x< 2^{30}$)。

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

第三行包含 $m$ 个整数 $b_1,b_2,\dots,b_m$ —— 数组 $B$ 的元素 ($0\le b_i< 2^{30}$)。

保证所有测试用例中 $n$ 的总和以及 $m$ 的总和均不超过 $500\,000$。

输出格式

对于每个测试用例,输出一个整数 —— 所求的最小 $k$。

子任务

子任务 分值 额外限制 需要完成的子任务
1 5 $n\le 2$
2 5 $n\le 5$ 1
3 5 $n\le 15$ 1,2
4 5 $n\le 100$ 1–3
5 5 $n\le 2000$ 1–4
6 10 $n\le 5000$ 1–5
7 5 $n\le 100000,\ m=2$
8 10 $n\le 100000,\ m=3$
9 5 $n,m\le 100000;\ a_i,b_i< 2$
10 10 $n,m\le 100000;\ a_i,b_i< 4$ 9
11 35 1–10

样例数据

标准输入

3
2 2 0
0 0
1 1
5 5 3
0 1 2 3 4
0 1 2 3 4
5 5 4
0 1 2 3 4
0 1 2 3 4

标准输出

1
4
5

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.