Subarrays XOR

4.3

7 votes
Medium-Hard
Problem

A straightforward question. Given an array of positive integers you have to print the number of subarrays whose XOR is less than K. Subarrays are defined as a sequence of continuous elements Ai, Ai+1, ..., Aj . XOR of a subarray is defined as Ai^Ai+1^ ... ^Aj. Symbol ^ is Exclusive Or

Input Format:

First line contains T, the number of test cases. Each of the test case consists of N and K in one line, followed by N space separated integers in next line.

Output Format:

For each test case, print the required answer. Constraints:

1 ≤ T ≤ 10

1 ≤ N ≤ 10^5

1 ≤ A[i] ≤ 10^5

1 ≤ K ≤ 10^6

Sum of N over all testcases will not exceed 10^5.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Only subarrays satisfying the conditions are [1],[1,3,2] and [3,2].

Editor Image

?