#C10400. Task Management with Priorities

    ID: 39602 Type: Default 1000ms 256MiB

Task Management with Priorities

Task Management with Priorities

You are given a series of commands to manage a set of tasks with integer priorities. There are three types of commands:

  • ADD x: Add a task with priority x to the list.
  • COMPLETE x: Mark the task with priority x as completed.
  • QUERY: Output the task with the smallest priority value that has not been completed. If there is no such task, output NONE.

The underlying data structure is a min-heap, and when a task is completed, it remains in the heap until it reaches the top when processing a query, at which point it is skipped. Your task is to implement this management system.

Note: If any formulas are needed, use LaTeX format. In this problem, the operations follow the standard min-heap behavior, where after an ADD operation the minimal element is always at the top.

inputFormat

The first line of input contains a single integer Q, representing the number of commands. The following Q lines each contain a command. Commands can be in one of the following formats:

  • ADD x: where x is an integer.
  • COMPLETE x: where x is an integer.
  • QUERY

Input is read from stdin.

outputFormat

For each QUERY command, output the smallest priority task that has not been completed. If no such task exists, output NONE. Each result should be printed on its own line to stdout.

## sample
2
ADD 5
QUERY
5