#K76052. Sarah's Stamp Collection
Sarah's Stamp Collection
Sarah's Stamp Collection
Sarah owns a collection of stamps. Initially, she has n stamps with given values. Then she performs q queries on her collection. Each query is in one of the following two forms:
- 1 v: Add a stamp with value v to the collection. If the stamp already exists, nothing happens.
- 2 v: Check if a stamp with value v is present in the collection. Print
YES
if it exists, orNO
otherwise.
The task is to process all queries. For each query of type 2, output the corresponding answer.
Note: The query operations modify the collection in real time. There is no need to worry about duplicates when adding; simply maintain the collection.
The mathematical model can be interpreted as managing a set \(S\) initially containing \(n\) elements. For each query:
- For type 1: \(S = S \cup \{v\}\).
- For type 2: Check if \(v \in S\) and report accordingly.
inputFormat
The input is given via standard input (stdin) and has the following format:
- The first line contains two integers \(n\) and \(q\), representing the number of initial stamps and the number of queries, respectively.
- The second line contains \(n\) space-separated integers, the values of the initial stamps. If \(n = 0\), this line will be empty.
- The next \(q\) lines each contain two integers. The first integer is the query type (either 1 or 2) and the second integer is the value \(v\).
outputFormat
For each query of type 2, output a single line containing YES
if a stamp with the given value exists in the collection, or NO
otherwise. Output is via standard output (stdout).
5 7
30 10 50 20 40
2 10
2 35
1 35
2 35
1 75
2 75
2 30
YES
NO
YES
YES
YES
</p>