#C7323. Integer Set Operations
Integer Set Operations
Integer Set Operations
You are required to implement an integer set with the following operations:
- add x: Add integer \( x \) to the set.
- delete x: Remove integer \( x \) from the set if it exists.
- exists x: Check whether integer \( x \) exists in the set. Output
YES
if it exists andNO
otherwise.
You will be provided a sequence of queries. Each query is given in the form "command x". Process the queries in order and output the results of all exists
queries.
The operations must be performed in an efficient manner. For example, for the exists
query, the answer should be based on the current state of the set after performing all previous operations.
inputFormat
The first line contains an integer \( Q \) which denotes the number of queries. Each of the next \( Q \) lines contains a query in one of the following formats:
add x
delete x
exists x
It is guaranteed that \( x \) is an integer.
outputFormat
For each query of type exists
, output a line containing either YES
or NO
depending on whether \( x \) is present in the set.
8
add 1
add 2
exists 1
exists 3
add 3
exists 3
delete 3
exists 3
YES
NO
YES
NO
</p>