#K47812. Unique List Management
Unique List Management
Unique List Management
You are given a series of operations to manage a list of unique integers. The operations are defined as follows:
- Operation \(1\): Insert an integer \(x\) into the list. If \(x\) is already in the list, do nothing.
- Operation \(2\): Remove an integer \(x\) from the list. If \(x\) is not present, do nothing.
- Operation \(3\): Query the current state of the list. When a query is issued in mode 1, output the list in ascending order, separated by spaces. If the list is empty, output
EMPTY
. In mode 2, this operation is ignored.
The program supports two modes:
- Mode 1: For every \(3\) operation, output the current list (sorted in ascending order) immediately.
- Mode 2: Process all operations and, at the end, output the final state of the list (sorted in ascending order). In this mode, any \(3\) operations encountered in the middle are ignored.
Note: All outputs must be printed to stdout, and all inputs are read from stdin.
inputFormat
The input is read from stdin and has the following format:
- An integer
mode
(either1
or2
). Mode 1 corresponds to query mode (each query is processed immediately) and Mode 2 corresponds to final state mode (only the final state is output). - An integer
n
indicating the number of operations. n
lines follow, each containing an operation in one of the following forms:1 x
— insert integer \(x\) into the list2 x
— remove integer \(x\) from the list3
— query the current status of the list (only used in Mode 1)
outputFormat
The output is written to stdout. Depending on the mode, the output should be:
- Mode 1: For every \(3\) operation, print a separate line containing the current list sorted in ascending order (elements separated by a single space). If the list is empty, print
EMPTY
. - Mode 2: After processing all operations, print a single line representing the final state of the list sorted in ascending order. If the list is empty, print
EMPTY
.
1
6
1 5
1 3
1 5
3
2 3
3
3 5
5
</p>