#C1238. 最大异或与值对

最大异或与值对

【题目描述】

小灰灰有一个长度为 nn 的非负整数序列 a1,a2,…,ana_1,a_2,\dots,a_n,序列里的每个数都小于 2m2^m。小蓝从中选出两个不同位置上的数 aia_i 与 aja_j(1≤i<j≤n1\le i<j\le n),再选出一个非负整数 xx(0≤x<2m0\le x<2^m),把这两个数分别异或上 xx 后按位与起来,得到的值是 $(a_i\operatorname{xor}x)\operatorname{and}(a_j\operatorname{xor}x)$。

小蓝希望这个值尽可能大。请你对每组数据求出它能达到的最大值:

$$\max_{1\le i<j\le n}\ \max_{0\le x<2^m}\big((a_i\operatorname{xor}x)\operatorname{and}(a_j\operatorname{xor}x)\big)$$

【输入描述】

第一行一个正整数 TT,表示数据组数。

接下来依次给出 TT 组数据,每组数据的格式如下:

  • 第一行两个正整数 nn 与 mm,表示序列的长度,以及序列中每个数的上界 2m2^m;
  • 第二行 nn 个非负整数 a1,a2,…,ana_1,a_2,\dots,a_n,相邻两个数之间用一个空格隔开。

保证:

  • T≤100T\le100;
  • 2≤n≤1052\le n\le10^5;
  • 1≤m≤301\le m\le30;
  • 0≤ai<2m0\le a_i<2^m;
  • 所有组中 nn 的和不超过 2×1052\times10^5。

【输出描述】

对每组数据输出一行一个整数,表示该组数据中 $(a_i\operatorname{xor}x)\operatorname{and}(a_j\operatorname{xor}x)$ 能取到的最大值。


【样例 1】

【样例 1 输入】

3
3 3
1 4 6
2 4
9 6
5 4
10 10 3 12 5

【样例 1 输出】

5
0
15

【样例 1 解释】

  • 第 11 组:取 a2=4a_2=4、a3=6a_3=6、x=1x=1,则 4xor⁡1=54\operatorname{xor}1=5、6xor⁡1=76\operatorname{xor}1=7,5and⁡7=55\operatorname{and}7=5。输出 5。
  • 第 22 组:取 a1=9a_1=9、a2=6a_2=6、x=0x=0,则 9xor⁡0=99\operatorname{xor}0=9、6xor⁡0=66\operatorname{xor}0=6,9and⁡6=09\operatorname{and}6=0;这一组无论怎么取,与值都只能是 00。输出 0。
  • 第 33 组:取 a1=10a_1=10、a2=10a_2=10、x=5x=5,则 10xor⁡5=1510\operatorname{xor}5=15,两个结果都是 1515,15and⁡15=1515\operatorname{and}15=15。输出 15。

【样例 2】

【样例 2 输入】

10
8 9
414 50 219 317 467 119 45 3
10 9
101 456 394 496 367 218 360 284 331 373
11 9
111 20 305 283 248 173 403 419 75 503 439
13 8
191 193 111 248 130 59 91 15 208 150 59 66 112
8 10
706 903 674 845 716 837 549 103
9 10
938 413 854 710 55 688 177 887 449
9 7
60 14 10 58 41 45 47 110 71
12 10
324 903 510 742 389 753 849 951 839 312 165 219
13 8
92 179 119 154 222 148 227 65 38 214 247 101 135
13 9
266 378 285 91 245 122 126 93 378 324 112 251 110

【样例 2 输出】

480
504
491
255
1015
990
125
1001
247
511

【数据规模与约定】

测试集编号 分数 特殊性质
1 10 n≤2000n\le2000
2 20 m≤10m\le10
3 70 无特殊性质