#P2839. [国家集训队] middle
[国家集训队] middle
Description
Given a sequence of length , let be the sorted version of . The median is defined as , where and are 0-indexed and the division takes the floor.
You are given a sequence of length .
Answer queries of the following type: among all subarrays of whose left endpoint is in and right endpoint is in , find the maximum possible median.
Here .
Positions are also 0-indexed.
I will use some method to force you to process the queries online.
Input Format
The first line contains the sequence length .
The next lines give the numbers of in order.
The next line contains .
Then lines follow, each containing . Let the answer to the previous query be (if this is the first query, then ).
Let the array $q=\{(a+x)\bmod n,(b+x)\bmod n,(c+x)\bmod n,(d+x)\bmod n\}$.
After sorting in ascending order, let the actual query be , , , .
The input is guaranteed to satisfy the conditions.
Output Format
Output lines in order, each giving the answer to a query.
5
170337785
271451044
22430280
969056313
206452321
3
3 1 0 2
2 3 1 4
3 1 4 0
271451044
271451044
969056313
Hint
For of the testdata, .
For an additional of the testdata, .
For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号