#K74907. Min Heap Implementation

    ID: 34301 Type: Default 1000ms 256MiB

Min Heap Implementation

Min Heap Implementation

You are given a sequence of commands to operate on a min-heap data structure. The min-heap supports the following operations:

  • insert x: Insert the integer x into the heap. The time complexity is \(O(\log n)\).
  • get_min: Retrieve the minimum element in the heap without removing it. If the heap is empty, output "Empty". This operation runs in \(O(1)\) time.
  • extract_min: Remove and return the minimum element from the heap. If the heap is empty, output "Empty". This operation runs in \(O(\log n)\) time.
  • size: Output the number of elements currently in the heap. This operation runs in \(O(1)\) time.

The input will be given via standard input and each operation which requires an output should immediately print its result to standard output.

Please note that all integer values will be within the range of 32-bit signed integers.

inputFormat

The first line of input contains a single integer n representing the number of commands.

Each of the following n lines contains one of the following commands:

  • insert x - insert the integer x into the heap
  • get_min - print the minimum element in the heap (or "Empty" if the heap is empty)
  • extract_min - remove and print the minimum element (or "Empty" if the heap is empty)
  • size - print the current number of elements in the heap

Input is read from standard input (stdin).

outputFormat

For each command that requires an output (get_min, extract_min, and size), output the result on a new line to standard output (stdout). No output is produced for the insert command.

## sample
5
insert 10
insert 20
insert 5
get_min
size
5

3

</p>