#P1946D. Birthday Gift

    ID: 75 远端评测题 2000ms 256MiB 尝试: 1 已通过: 0 难度: 6 上传者: 标签>bitmasksbrute forceconstructive algorithmsgreedyimplementation*1900

Birthday Gift

Description

Yarik's birthday is coming soon, and Mark decided to give him an array $a$ of length $n$.

Mark knows that Yarik loves bitwise operations very much, and he also has a favorite number $x$, so Mark wants to find the maximum number $k$ such that it is possible to select pairs of numbers [$l_1, r_1$], [$l_2, r_2$], $\ldots$ [$l_k, r_k$], such that:

  • $l_1 = 1$.
  • $r_k = n$.
  • $l_i \le r_i$ for all $i$ from $1$ to $k$.
  • $r_i + 1 = l_{i + 1}$ for all $i$ from $1$ to $k - 1$.
  • $(a_{l_1} \oplus a_{l_1 + 1} \oplus \ldots \oplus a_{r_1}) | (a_{l_2} \oplus a_{l_2 + 1} \oplus \ldots \oplus a_{r_2}) | \ldots | (a_{l_k} \oplus a_{l_k + 1} \oplus \ldots \oplus a_{r_k}) \le x$, where $\oplus$ denotes the operation of bitwise XOR, and $|$ denotes the operation of bitwise OR.

If such $k$ does not exist, then output $-1$.

Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The following lines contain the descriptions of the test cases.

The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5, 0 \le x < 2^{30}$) — the length of the array $a$ and the number $x$ respectively.

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i < 2^{30}$) — the array $a$ itself.

It is guaranteed that the sum of the values of $n$ across all test cases does not exceed $10^5$.

For each test case, output a single integer on a separate line — the maximum suitable number $k$, and $-1$ if such $k$ does not exist.

Input

Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The following lines contain the descriptions of the test cases.

The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5, 0 \le x < 2^{30}$) — the length of the array $a$ and the number $x$ respectively.

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i < 2^{30}$) — the array $a$ itself.

It is guaranteed that the sum of the values of $n$ across all test cases does not exceed $10^5$.

Output

For each test case, output a single integer on a separate line — the maximum suitable number $k$, and $-1$ if such $k$ does not exist.

描述

Yarik 的生日即将到来,Mark 决定送他一个长度为 nn 的数组 aa

Mark 知道 Yarik 非常喜欢位运算,并且他有一个最喜欢的数字 xx,所以 Mark 想找到一个最大的数 kk,使得可以选择一些数对 [l1,r1l_1, r_1], [l2,r2l_2, r_2], \ldots [lk,rkl_k, r_k],满足以下条件:

  • l1=1l_1 = 1
  • rk=nr_k = n
  • 对于所有 ii11kkliril_i \le r_i
  • 对于所有 ii11k1k - 1ri+1=li+1r_i + 1 = l_{i + 1}
  • $(a_{l_1} \oplus a_{l_1 + 1} \oplus \ldots \oplus a_{r_1}) | (a_{l_2} \oplus a_{l_2 + 1} \oplus \ldots \oplus a_{r_2}) | \ldots | (a_{l_k} \oplus a_{l_k + 1} \oplus \ldots \oplus a_{r_k}) \le x$,其中 \oplus 表示按位异或操作,| 表示按位或操作。

如果不存在这样的 kk,则输出 1-1

输入

每个测试包含多个测试用例。第一行包含一个整数 tt (1t1041 \le t \le 10^4) — 测试用例数量。接下来的行包含测试用例的描述。

每个测试用例的第一行包含两个整数 nnxx (1n105,0x<2301 \le n \le 10^5, 0 \le x < 2^{30}) — 数组 aa 的长度和数字 xx

每个测试用例的第二行包含 nn 个整数 a1,a2,,ana_1, a_2, \ldots, a_n (0ai<2300 \le a_i < 2^{30}) — 数组 aa 本身。

保证所有测试用例中 nn 的总和不超过 10510^5

输出

对于每个测试用例,输出一个整数表示最大合适的数 kk,如果不存在这样的 kk,则输出 1-1

8
3 1
1 2 3
2 2
1 1
2 2
1 3
2 3
0 0
3 2
0 0 1
4 2
1 3 3 7
2 2
2 3
5 0
0 1 2 2 1
2
2
1
2
3
-1
1
2

注意

  • 在第一个测试用例中,可以取 kk 等于 22,选择两个段 [1,11, 1] 和 [2,32, 3],(1)(23)=1(1) | (2 \oplus 3) = 1。可以证明 22 是可能的最大答案。
  • 在第二个测试用例中,段 [1,11, 1] 和 [2,22, 2] 是合适的,(1)(1)=1(1) | (1) = 1。不可能选择更多的段。
  • 在第三个测试用例中,不可能选择 22 个段,因为 (1)(3)=3>2(1) | (3) = 3 > 2,所以最佳答案是 11