NOI Contest Archive

Archive / 2024 / Final Round — Day 2

central-scroll

Medium · National Olympiad in Informatics Sri Lanka 2024 - Day 2

In the historic kingdom of Numeria lies the famous Grand Library, a treasure trove of ancient scrolls kept in \(n\) special cases, each labeled from \(T_0\) to \(T_{n-1}\). These scrolls are unique as each contains a numeric value representing the importance of a specific historical event, and the scrolls within each case are meticulously sorted by these importance values.

Scholars frequent this library, eager to analyze historical trends by comparing events between any two selected cases. The head librarian, aiming to facilitate these scholarly investigations, seeks to automate the process of finding the central event importance when two cases are chosen for comparison.

Here’s your challenge: Given the \(n\) cases of scrolls, you will process \(Q\) queries from visiting scholars. Each query specifies two indices \(i\) and \(j\) \((0 \leq i, j \leq n-1)\), which correspond to the cases they have selected.

Your task is to quickly determine the importance of the event at the midpoint after combining the scrolls from cases \(T_i\) and \(T_j\) and sorting the combined case by importance values. It is guaranteed that the total number of scrolls in any pair of selected cases is always odd.

Can you devise a system that accurately and efficiently computes the central importance of the historical events, aiding the scholars in their pursuit of knowledge?

Input Format

Output Format

Constraints

Subtask - 40 pts

Limits

Sample Input 0

3 2
3 1 3 8
4 2 7 10 15
3 4 6 9
0 1
1 2

Sample Output 0

7
7