#P3871. [TJOI2010] 中位数
[TJOI2010] 中位数
Description
Given an integer sequence of elements, there are two operations:
- : Append an integer to the end of the sequence, forming a sequence of length .
- : Output the median of the current sequence.
The median is the number that lies in the middle after sorting the sequence in non-decreasing order. If the sequence length is even, it is the smaller of the two middle numbers.
Example 1: has median .
Example 2: has median .
Example 3: has median .
Input Format
The first line contains the initial sequence length .
The second line contains integers, representing the sequence, separated by spaces.
The third line contains the number of operations , meaning you will perform operations.
Then follow lines, each in the format described above.
Output Format
For each operation, output the value of the median.
6
1 2 13 14 15 16
5
add 5
add 3
mid
add 20
mid
5
13
Hint
Constraints
- For of the testdata, , .
- For of the testdata, , .
The absolute value of each integer in the sequence does not exceed , and numbers in the sequence may repeat.
Translated by ChatGPT 5
京公网安备 11011102002149号