#K62347. Dynamic Median Finder
Dynamic Median Finder
Dynamic Median Finder
This problem requires you to implement a data structure that supports dynamically adding numbers and querying the median. You must handle two types of operations:
- ADD x: Insert the integer x into the data structure.
- MEDIAN: Output the current median of all inserted numbers. When the number of elements is even, the median is defined as \(\frac{a+b}{2}\), where a and b are the two middle numbers.
The median value should be printed with one decimal place of precision.
inputFormat
The first line contains an integer \(Q\) representing the number of queries. Each of the next \(Q\) lines contains a query in one of the following formats:
- ADD x: where x is an integer that should be added to the data structure.
- MEDIAN: which requires you to output the median of the numbers added so far.
outputFormat
For each MEDIAN query, output the median of the current numbers on a new line. The median should be printed in decimal format with one digit after the decimal point.
## sample8
ADD 1
ADD 2
MEDIAN
ADD 3
MEDIAN
ADD 4
ADD 5
MEDIAN
1.5
2.0
3.0
</p>