#C3827. Median Maintenance Operations

    ID: 47297 Type: Default 1000ms 256MiB

Median Maintenance Operations

Median Maintenance Operations

You are given a list of operations to perform on a dynamic multiset of integers. The operations include insertion, deletion, and a median query. The median is defined as follows: if there are \(n\) elements after sorting, when \(n\) is odd, the median is the element at position \((n+1)/2\); when \(n\) is even, the median is the average of the two middle elements, i.e., \(\frac{x_{n/2}+x_{n/2+1}}{2}\). If the multiset is empty when a median query is performed, output "Empty".

The operations are specified in one of the following ways:

  • 1 x: Insert integer \(x\) into the multiset.
  • 2 x: Delete one occurrence of integer \(x\) from the multiset. If \(x\) is not in the multiset, do nothing.
  • 3: Query and output the current median.

Note that duplicate elements are allowed in the multiset.

inputFormat

The first line contains an integer \(T\) indicating the number of operations. The next \(T\) lines each contain an operation in one of the following formats:

  • 1 x: insert the integer \(x\).
  • 2 x: delete one occurrence of the integer \(x\).
  • 3: output the median of the current multiset.

outputFormat

For each median query (operation type 3), output the median on a new line. If the multiset is empty, output "Empty". If the median is the average of two numbers, output it as a float (if it is not an integer).

## sample
8
1 3
1 10
1 5
3
2 5
3
2 3
3
5

6.5 10

</p>