#C3057. Taco Book Catalog Operations
Taco Book Catalog Operations
Taco Book Catalog Operations
You are given a sequence of operations on a book catalog. The catalog supports two kinds of operations:
- Add Operation: "1 <book_title>" — Add a book with the given title to the catalog.
- Check Operation: "2 <book_title>" — Check whether a book with the given title exists in the catalog. If it exists, output
YES
; otherwise, outputNO
.
The program should process operations in the given order. Note that a book title may be added more than once (but is stored only once). For each check operation, output the corresponding result on a new line.
Note: In the solution below, the operations are processed as they appear. The expected complexity is efficient enough using set data structures.
Mathematically, if we denote the catalog set by \(B\), then for any check operation with title \(t\), the output is \[ output = \begin{cases} YES, & \text{if } t \in B,\\ NO, & \text{if } t \notin B. \end{cases} \]
inputFormat
The first line contains an integer N
representing the number of operations.
Each of the following N
lines contains an operation in one of the following formats:
1 <book_title>
— Add a book with the given title.2 <book_title>
— Check if the book exists in the catalog.
Note that <book_title>
may contain spaces.
outputFormat
For each check operation (operation type "2"), output a line containing either YES
if the book exists or NO
if it does not.
6
1 Pride and Prejudice
1 The Great Gatsby
2 Pride and Prejudice
2 Moby Dick
1 Moby Dick
2 Moby Dick
YES
NO
YES
</p>