#P10237. [yLCPC2024] E. Latent Kindom
[yLCPC2024] E. Latent Kindom
Background
Fusu and Teacher 10circle are playing the newest and hottest song Latent Kindom (LK) together on one setup.
The song LK has charts of different difficulties. The chart of difficulty has notes, which are , forming a sequence.
Fusu wants to know: if she plays the chart of difficulty and Teacher 10circle plays the chart of difficulty , what is the median of the note sequence after merging the two sequences?
Background
Fusu and Teacher 10circle are playing the newest and hottest song Latent Kindom (LK) together on one setup.
The song LK has charts of different difficulties. The chart of difficulty has notes, which are , forming a sequence.
Fusu wants to know: if she plays the chart of difficulty and Teacher 10circle plays the chart of difficulty , what is the median of the note sequence after merging the two sequences?
Problem Description
You are given sequences . You need to answer queries. Each query gives , and you must find the median of the sequence obtained by concatenating and .
Concatenating two sequences means writing the numbers of sequence one by one after sequence . If the resulting sequence has length , the median is defined as the -th smallest number in the sequence. Here, denotes the smallest integer that is not less than .
Note that the queries in this problem are independent. That is, although you are asked for the median after concatenating and , you will not actually perform any concatenation operation on the sequences.
Input Format
This problem contains multiple testcases within a single test point. The first line of the input is a positive integer , indicating the number of testcases. For each testcase:
The first line contains two integers (), representing the number of sequences and the number of queries.
The next lines each describe a sequence. In the -th line, the first integer is (), the length of sequence . Then follow integers, representing sequence . It is guaranteed that all numbers in the sequences are positive integers not greater than .
The next lines each contain two integers (, ), representing a query.
It is guaranteed that, within a single test point, the sums of , , and all do not exceed .
Output Format
For each query of each testcase, output one line with one integer, representing the answer.
1
3 3
1 1
2 2 3
3 4 5 6
1 2
1 3
2 3
2
4
4
Hint
Hint
Please note that reading and writing a large amount of data can affect the program’s efficiency. Use appropriate input/output methods, do not flush the output buffer frequently, and avoid TLE.
Translated by ChatGPT 5