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的个数