D1. 388535 (Easy Version)

Problem - D1 - Codeforces

D1. 388535 (Easy Version)

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

This is the easy version of the problem. The difference in the constraints between both versions is 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 performs the following steps:

  • First, Gojou chooses 22 integers ll and rr such that l≤rl≤r.
  • Then, Gojou makes an array aa of length r−l+1r−l+1 which is a permutation of the array [l,l+1,…,r][l,l+1,…,r].
  • Finally, Gojou chooses a secret integer xx and sets aiai to ai⊕xai⊕x for all ii (where ⊕⊕ denotes the bitwise XOR operation).

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

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

Input

The first line contains a single integer tt (1≤t≤1051≤t≤105) — the number of test cases.

In the first line of each test case contains two integers ll and rr (0=l≤r<2170=l≤r<217).

The second line contains r−l+1r−l+1 integers of a1,a2,…,ar−l+1a1,a2,…,ar−l+1 (0≤ai<2170≤ai<217). It is guaranteed that aa can be generated using the steps performed by Gojou.

It is guaranteed that the sum of r−l+1r−l+1 over all test cases does not exceed 217217.

Output

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

Example

input

Copy

3
0 3
3 2 1 0
0 3
4 7 6 5
0 2
1 2 3

output

Copy

0
4
3

Note

In the first test case, the original array is [3,2,1,0][3,2,1,0].

In the second test case, the original array is [0,3,2,1][0,3,2,1].

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

//#include<bits/stdc++.h>
#include<iostream>
#include<vector>
using namespace std;

int main() {

	ios::sync_with_stdio(false);
	cin.tie(0);
	int tt;
	cin >> tt;
	while (tt--) {
		int l, r;
		cin >> l >> r;
		vector<int> cc(30);
		for (int i = 0; i < r - l + 1; i++) {
			int x;
			cin >> x;
			for(int j=0;j<30;j++)
			cc[j] += (x >> j) & 1;
		}
		int ans = 0;
		for (int i = 0; i < 30; i++) {
			if (cc[i] > (r - l + 1) - cc[i]) {
				ans += (1 << i);
			}
		}
		cout << ans << "\n";
	}
	return 0;
}

统计每个位置1的个数

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值