Codeforces Round 956 (Div. 2) and ByteRace 2024
F
array-value
Codeforces
2500
原题
← EG →
翻译中…

You have an array of non-negative integers $a_1, a_2, \ldots, a_n$.

翻译中…

The value of a sub-array of length $\ge 2$, $a[l, r] = [a_l, a_{l+1}, \ldots, a_r]$ is the minimum value of $a_i \oplus a_j$ such that $l \le i \lt j \le r$, where $\oplus$ is the xor (exclusive-or) operator.

翻译中…

You have to find the $k$-th smallest value over all sub-arrays of length $\ge 2$.

翻译中…

Input

翻译中…

The first line of the input contains multiple test cases $t$ ($1 \le t \le 2 \cdot 10^4$).

翻译中…

The first line of each test case contains integer numbers $n$ and $k$ ($2 \le n \le 10^5$, $1 \le k \le \frac{n\cdot(n-1)}{2}$).

翻译中…

The second line of the input contains $n$ non-negative integer numbers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 10^9$) — the array itself.

翻译中…

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

翻译中…

Output

翻译中…

Print the $k$-th smallest value obtained over all subarrays of length at least $2$.

翻译中…

Note

翻译中…

In the first testcase, we have subarrays with their smallest exclusive-or pair as:

翻译中…

$[1,2]: 3$

翻译中…

$[2,3]: 1$

翻译中…

$[3,4]: 7$

翻译中…

$[4,5]: 1$

翻译中…

$[1,2,3]: 1$

翻译中…

$[2,3,4]: 1$

翻译中…

$[3,4,5]: 1$

翻译中…

$[1,2,3,4]: 1$

翻译中…

$[2,3,4,5]: 1$

翻译中…

$[1,2,3,4,5]: 1$

翻译中…

The sorted order would be: $1, 1, 1, 1, 1, 1, 1, 1, 3, 7$. Therefore, the second smallest element would be $1$.

翻译中…

样例

Input #1
4
5 2
1 2 3 4 5
2 1
4 3
4 6
1 2 4 8
5 9
1 2 3 4 5
Output #1
1
7
12
3
InputCopy OutputCopy
题目信息
题号
1983F
时间限制
4 s
内存限制
256 MB
标签
二分
位运算
数据结构
贪心
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。