Codeforces Round 779 (Div. 2)
D2
388535 (Hard Version)
Codeforces
2300
原题
← D1E →
翻译中…

This is the hard version of the problem. The difference in the constraints between both versions are colored below in red. You can make hacks only if all versions of the problem are solved.

翻译中…

Marin and Gojou are playing hide-and-seek with an array.

翻译中…

Gojou initially perform the following steps:

翻译中…
  • First, Gojou chooses $2$ integers $l$ and $r$ such that $l \leq r$.
  • Then, Gojou will make an array $a$ of length $r-l+1$ which is a permutation of the array $[l,l+1,\ldots,r]$.
  • Finally, Gojou chooses a secret integer $x$ and sets $a_i$ to $a_i \oplus x$ for all $i$ (where $\oplus$ denotes the bitwise XOR operation).
翻译中…

Marin is then given the values of $l,r$ and the final array $a$. She needs to find the secret integer $x$ to win. Can you help her?

翻译中…

Note that there may be multiple possible $x$ that Gojou could have chosen. Marin can find any possible $x$ that could have resulted in the final value of $a$.

翻译中…

Input

翻译中…

The first line contains a single integer $t$ ($1 \leq t \leq 10^5$) — the number of test cases.

翻译中…

In the first line of each test case contains two integers $l$ and $r$ ($\color{red}{\boldsymbol{0} \boldsymbol{\le} \boldsymbol{l}} \le r \lt 2^{17}$).

翻译中…

The second line contains $r - l + 1$ space-seperated integers of $a_1,a_2,\ldots,a_{r-l+1}$ ($0 \le a_i \lt 2^{17}$). It is guaranteed that array $a$ is valid.

翻译中…

It is guaranteed that the sum of $r - l + 1$ over all test cases does not exceed $2^{17}$.

翻译中…

Output

翻译中…

For each test case print an integer $x$. If there are multiple answers, print any.

翻译中…

Note

翻译中…

In the first test case, the original array is $[7, 6, 5, 4]$.

翻译中…

In the second test case, the original array is $[4, 7, 6, 5]$.

翻译中…

In the third test case, the original array is $[3, 1, 2]$.

翻译中…

样例

Input #1
3
4 7
3 2 1 0
4 7
4 7 6 5
1 3
0 2 1
Output #1
4
0
3
InputCopy OutputCopy
题目信息
题号
1658D2
时间限制
1 s
内存限制
256 MB
标签
位运算
暴力
数据结构
数学

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