XOR Minimum

View as PDF

Submit solution

Points: 17 (partial)
Time limit: 2.0s
Memory limit: 128M

Authors:
Problem type

Given a 0-indexed list of N non-negative integers, and Q queries each consisting of one non-negative integer x, output the smallest index of the minimum value in the list after each number in the list is XOR'd with x for each query. Queries are persistent. That is, any previous queries change the list directly and affect the current query's answer.

Input Specification

The first line will contain two space-separated integers, N (1N105), and Q (1Q105).

The second line will contain N space-separated integers, a1,a2,,aN (0ai109).

The next Q lines will each contain one integer x (0x109).

Output Specification

For each query, output the smallest index of the minimum value in the list after every number in the list has been XOR'd with x.

Subtasks

For all subtasks, 1N105 and 1Q105

For 5 out of the 17 available marks, 1N104 and 1Q104

Sample Input 1

Copy
8 4
2 15 8 1 6 2 16 8
0
2
10
7

Sample Output 1

Copy
3
0
2
1

Explanation for Sample Output 1

Copy
2 15 8 1 6 2 16 8

The array is unchanged after the first XOR operation. The minimum is simply 1 at index 3.

Copy
0 13 10 3 4 0 18 10

In this case, the first of the two zeroes is chosen (index 0).

Copy
10 7 0 9 14 10 24 0

The first occurrence of the minimum value (0) is at index 2.

Copy
13 0 7 14 9 13 31 7

The minimum value (0) is at index 1.

Sample Input 2

Copy
7 5
7 7 8 0 0 10 16
12
14
16
6
12

Sample Output 2

Copy
2
3
6
6
6

Comments

There are no comments at the moment.