Minimum XOR

5

1 votes
Probablity, Bit manipulation, Basic Programming, Pigeon Hole Principle, Math
Problem

You're given an array A of N non-negative integers and Q queries. In each query, you're given two integers L and R (1L<RN). Find min(A[i]A[j]) (Li<jR) for each query, where is the bitwise XOR operator.

Input format

The first line contains two integers N and Q as described in the statement.

The second line contains N space-seperated integers denoting the elements of the array A.

Each of the following Q lines contain two integers L and R, as described in the statement.

Output format

The output must contain Q lines, where each line contains the answer for the corresponding query.

Constraints

1N,Q105

1A[i]210

Sample Input
5 2
1 2 3 4 5
1 2
2 5
Sample Output
3
1
Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

In the first query, we can only choose i=1 and j=2, so the answer is 3 as a[1]a[2]=12=3.

In the second query, we can choose i=2 and j=3, so the answer is 1

Editor Image

?