luogu#P10765. 「CROI · R2」在相思树下 I
「CROI · R2」在相思树下 I
Background
Year after year under the peach tree,
Watching one become two.
Little wishes often gestured,
"Come true soon, please do!"
Yet unaware of his presence beneath the same tree.
Though "meeting" seems separated by the ends of the earth,
Around the corner, fate brings us together—
Oh, destiny, destiny!
Problem Description
This problem uses multiple test cases.
Xinxin has a sequence from to and wants to perform the following two operations:
Operation 1: Delete all elements at odd positions.
Operation 2: Delete all elements at even positions.
After performing operations, exactly one number remains. Given the sequence of operations, determine the final remaining number.
Input Format
- The first line contains a positive integer , the number of test cases.
- For each test case:
- The first line contains two integers and .
- The second line contains integers representing the operations (1 for Operation 1, 2 for Operation 2).
Output Format
Output lines, each containing the answer for the corresponding test case.
4
5 2
1 1
8 3
2 2 2
8 3
1 1 1
8 3
1 2 1
4
1
8
6
Hint
Explanation
Sample Explanation:
For the first test case, the sequence evolves as:
.
Constraints
- For of the data: .
- For of the data:
- ,
- .
- It is guaranteed that exactly one number remains after operations for all test cases.