import java.util.Scanner; /** * @author supermejane * @date 2025/10/12 * @description BGN85 Poi 的新加法(Easy Version) */ public class Main { public static void main(String[] args) { //1.首先把题目意思搞懂f(x, y) = x + y - (x ^ y)其实按题目的第一次进位我是理解不了,一开始以为是只保留第一次进位结果错了 //直接从公式理解,就是只有x, y对应都为1的位置才会保留,如果位置只有一个1,因为异或之后为1,实际后面会减去,所以不用保留,所以 //实际上就是包括都为1的位置~(result ^ in.nextLong()) & result,因为是相同的直接<< 1 //2.注意题目的每组测试数据是单独计算时间的,即每组不超过1s, 不是全加起来超过1s, 所以时间复杂度不是o(n * m)而是o(m) Scanner in = new Scanner(System.in); int n = in.nextInt(); while (n-- > 0) { //一组m个元素 long m = in.nextLong(), result = 0, query = in.nextLong(); for (int i = 0; i < m; i++) { result = i > 0 ? ~(result ^ in.nextLong()) & result : in.nextLong(); if (result > 0 && i > 0) { // int cnt = 0; // while ((result & 1) == 0) { // cnt++; // result >>= 1; // } // result = 1 << (cnt + 1); result <<= 1; } } int l = in.nextInt(), r = in.nextInt(); System.out.println(result); } } }