AlgoUniversity
  • Go Back
Discussion
XOR Subarrays :

Author

Ayush Gangwani

Difficulty Level : Hard

Submissions : 945

Asked In : Google

Marks :20

: 16 | : 3

You are given an Array $$$A$$$ containing $$$n$$$ integers and an integer $$$x$$$.

Find the minimum value $$$k$$$ such that the number of subarrays of $$$A$$$ having $$$XOR$$$ value of at most $$$k$$$ is atleast $$$x$$$.

An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself. The $$$XOR$$$ value of a subarray is the $$$XOR$$$ of values of elements in the subarray.

Input

The first line of input contains an integer $$$t$$$ $$$(1 \le t \le 10^3)$$$ — the number of testcases.

The first line of each testcase contains two space separated integers $$$n$$$ $$$(1 \le n \le 5 \cdot 10^{4})$$$ and $$$x$$$ $$$(1 \le x \le n*(n+1)/2)$$$ — the number of elements in the array $$$A$$$ and the value of $$$x$$$ as described in the problem statement.

The second line consists of $$$n$$$ space separated integers - $$$A_1, A_2......., A_n$$$ $$$(1 \le A_i \le 10^6)$$$ — the elements of the array $$$A$$$.

It is guaranteed that the sum of $$$n$$$ over all testcases does not exceed $$$5 \cdot 10^4$$$.

Output

For each test case, print the minimum value of $$$k$$$ satisfying the constraints in a single new line.

Example

Input
1
4 7
1 2 3 4
Output
4

Note

In sample test case,

Given number of subarrays to be atleast $$$7$$$, i.e. $$$x = 7.$$$

So if we select the value for $$$k$$$ to be $$$3$$$, number of subarrays of $$$A$$$ having $$$XOR$$$ value atmost $$$3$$$ is $$$6$$$.

If we select the minimum value for $$$k$$$ to be $$$4$$$, number of subarrays of $$$A$$$ having $$$XOR$$$ value atmost $$$4$$$ is $$$8$$$.

So, the minimum value of $$$k$$$ for which number of subarrays of $$$A$$$ is atleast $$$7$$$, each of which have $$$XOR$$$ value of atmost $$$k$$$ is $$$4$$$.

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.