E. Compatible Numbers
time limit per test4 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Two integers x and y are compatible, if the result of their bitwise “AND” equals zero, that is, a & b = 0. For example, numbers 90 (10110102) and 36 (1001002) are compatible, as 10110102 & 1001002 = 02, and numbers 3 (112) and 6 (1102) are not compatible, as 112 & 1102 = 102.
You are given an array of integers a1, a2, …, an. Your task is to find the following for each array element: is this element compatible with some other element from the given array? If the answer to this question is positive, then you also should find any suitable element.
Input
The first line contains an integer n (1 ≤ n ≤ 106) — the number of elements in the given array. The second line contains n space-separated integers a1, a2, …, an (1 ≤ ai ≤ 4·106) — the elements of the given array. The numbers in the array can coincide.</

该博客探讨了在编程竞赛中遇到的E. Compatible Numbers问题,主要涉及位运算的概念。题目要求找出数组中每对元素是否能使得它们的按位与结果为0,即两数兼容。对于每个输入的数组元素,需要判断是否存在另一个元素与其兼容,并给出这样的配对。博客提供了一些样例测试用例和解决方案,包括使用DP预处理方法来解决这个问题。
最低0.47元/天 解锁文章
2226

被折叠的 条评论
为什么被折叠?



