Maximum XOR

You are given an array of n integers, and you need to process q queries. Each query consists of a single integer , and your task is to find the maximum XOR (exclusive OR) value between the given integer and any element in the array.


The first line of the input contains two space-separated integers, n (1 ≤ n ≤ 100 000) and q (1 ≤ q ≤ 100 000), representing the size of the array and the number of queries, respectively.
The second line contains n space-separated integers, (), representing the elements of the array.
The following q lines each contain a single integer, (), representing a query integer.


For each query, output a single integer on a new line, representing the maximum XOR value between the query integer and any element from the array.
4 3 7 2 5 3 0 2 7
7 7 5


Time limit: 8 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue