#P7485. 「Stoi2031」枫
「Stoi2031」枫
Description
Dong really likes maple leaves. There is a maple tree in front of her house, and leaves have fallen from it. Dong numbers them from to . She does not want these maple leaves to be stepped on and rot on the ground, so she decides to pick them up.
She calls the following process a retrieval: sort the remaining unpicked maple leaves by their numbers in increasing order or decreasing order, pick up the first leaf, then pick up one leaf every leaves. She will keep performing retrieval. The first retrieval is from small to large; after that, each retrieval uses the opposite order of the previous one (i.e., if last time was from small to large, this time is from large to small, and vice versa), until the last leaf is also picked up.
She believes the last leaf picked up represents longing, which can bring happiness. She wants more happiness, so she will ask you many times: for given values of and , what is the number of the longing leaf.
Input Format
The first line contains the number of test groups , satisfying , where is the testdata point ID.
Lines to : each line starts with two integers , meaning she will take queries, and in each query the number of leaves does not exceed . Then integers follow, each being the value of for one query. For all queries on line , .
Output Format
For each line, output integers, representing the answers to the queries on that line.
1
2 3 1 3
1 2
2
2 3 1 3
3 7 2 4 7
1 2
2 2 5
3
2 3 1 3
3 7 2 4 7
7 10 1 2 3 6 7 8 10
1 2
2 2 5
1 2 2 3 4 6 6
Hint
Brief statement:
Given , repeatedly operate on . In each operation, alternately take numbers in increasing order or decreasing order, and remove the current -th number (where and does not exceed the total count of remaining numbers). Find the number removed last. There are multiple queries.
Sample explanation:
Due to space limits, only sample is explained.
For line :
For the first query, there is only maple leaf on the ground, which is the longing.
For the second query, in Dong's first retrieval, she picks up leaves in order; after turning around, only remains, which is the longing.
For line :
For the first query, in Dong's first retrieval, she picks up leaf ; after turning around, remains, which is the longing.
For the second query, in Dong's first retrieval, she picks up leaves ; in the second retrieval, she picks up ; remains, which is the longing.
For the third query, Dong first picks up , then picks up , then picks up ; now remains, which is the longing.
Constraints:
For each testdata point of this problem (except the st), the input data is exactly the same as the previous testdata point, except for the number of test groups and the last line (line ). The constraints and special limits of each testdata point are as follows.
| Testdata No. | Special limit | Score | ||
|---|---|---|---|---|
| Sample | ||||
| Sample | ||||
| Sample | ||||
| None | ||||
The input size of this problem is large. You may choose to use the fast input template provided in the contest statement to speed up reading.
Translated by ChatGPT 5
京公网安备 11011102002149号