#P1366. 有序表的合并
有序表的合并
Description
Given two sequences , both sorted in non-decreasing order. It is guaranteed that there are no duplicate numbers in .
Now, for each number in , determine how many times it appears in .
Input Format
There are multiple test cases in a single test file.
The first line contains an integer , the number of test cases. Then, for each test case, the input is given as follows:
- The first line contains two integers, the lengths of sequences and , denoted by and .
- The second line contains integers representing sequence , where the -th integer is .
- The third line contains integers representing sequence , where the -th integer is .
Output Format
To avoid excessive output, for each test case, output a single integer on one line: the bitwise XOR sum of the occurrence counts of every number of in .
Formally, let appear times in . You need to output , where denotes the bitwise XOR operation. You may refer to the Hint to complete the computation.
1
3 5
1 3 6
1 3 3 5 5
3
1
9 4
1 2 3 4 5 6 7 8 9
1 1 4 5
2
2
3 5
1 3 6
1 3 3 5 5
9 4
1 2 3 4 5 6 7 8 9
1 1 4 5
3
2
Hint
Explanation of Sample 1
- appears time in .
- appears times in .
- appears times in .
Therefore, the output is .
Explanation of Sample 2
appear times in , respectively, so the output is .
Constraints
For all test files, it is guaranteed that:
- ;
- , and ;
- , and , .
Here, denotes the sum of all and within a single test file, i.e., the total length of the input sequences does not exceed .
Notes
- Pay attention to the impact of large input on program efficiency. Choose an appropriate input method to avoid timeouts.
- Use suitable data types to store variables to avoid overflow.
- If you do not know what a bitwise XOR sum is, you can add the following function to your code:
template <class T>
T getXorSum(T *begin, T *end) {
T ret = 0;
for (T *it = begin; it != end; ++it) ret ^= *it;
return ret;
}
This function computes the bitwise XOR sum over a half-open interval of the given array (including std::vector). The return type matches the type of the input array. The usage is similar to std::sort. For example, to compute the bitwise XOR sum of , call getXorSum(a + 1, a + 1 + n). To compute the bitwise XOR sum of , call getXorSum(a, a + n). If is a std::vector, replace a in the calls above with a.begin() accordingly.
Translated by ChatGPT 5
京公网安备 11011102002149号