#C6444. Maintain Unique Sample IDs
Maintain Unique Sample IDs
Maintain Unique Sample IDs
You are given a sequence of operations to perform on a collection of sample IDs. Each operation is one of the following:
insert x
: Insert the sample ID x into the collection. If x is already present, ignore the command.remove x
: Remove the sample ID x from the collection. If x is not present, do nothing.size
: Output the current number of sample IDs in the collection.
After processing all operations, output the final sorted list of unique sample IDs. Mathematically, if we denote the collection by \(S\), then initially \(S=\emptyset\) and for each operation:
[ \text{insert } x: S = S \cup {x}, \quad \text{remove } x: S = S \setminus {x}, \quad \text{size}: output;|S|. ]
The final output consists of one line for each size
operation (showing the size of the collection at that moment) followed by one additional line showing the sorted collection of sample IDs (space separated). If the collection is empty, print an empty line.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains an integer n representing the total number of operations.
- The following n lines each contain a single operation. An operation can be in one of the forms:
insert x
remove x
size
outputFormat
For every size
command encountered, output the current count of sample IDs on a new line. After processing all operations, output the final sorted list of unique sample IDs on one line, with the values separated by spaces. If there are no sample IDs, output an empty line.
7
insert 10
insert 5
size
insert 15
size
remove 10
size
2
3
2
5 15
</p>