#K38612. Library Query Manager

    ID: 26238 Type: Default 1000ms 256MiB

Library Query Manager

Library Query Manager

You are given a library system where you need to manage a collection of books across different categories. The system supports the following operations:

  1. Add a book: Insert a book into a specific category. The query is formatted as: 1 <category> <book_id>. When adding, the books in each category must be maintained in sorted order.

  2. Delete a book: Remove a book from a specific category. The query is formatted as: 2 <category> <book_id>. If the book does not exist in that category, no action is performed.

  3. Retrieve the k-th smallest book: Query the k-th smallest book ID in the specified category. The query is formatted as: 3 <category> <k>. Here, (k) is 1-indexed. If (k) exceeds the number of books in the category, output "invalid".

Your task is to process all queries and, for each type 3 query, output the corresponding result.

The sorted order maintained for each category means that if a category contains books with IDs (a_1, a_2, \ldots, a_m), then (a_1 \le a_2 \le \cdots \le a_m).

inputFormat

The input is given via standard input (stdin). The first line contains an integer ( n ) representing the number of queries. Each of the following ( n ) lines contains a query in one of the following formats:

1 <category> <book_id> – to add a book to the library. • 2 <category> <book_id> – to delete a book from the library. • 3 <category> <k> – to retrieve the k-th smallest book ID from the library.

outputFormat

For each query of type 3, output the result on a new line to standard output (stdout). The result is either the k-th smallest book ID in that category or "invalid" if the query is out of bounds.## sample

3
1 Fantasy 1001
1 Fantasy 500
3 Fantasy 1
500

</p>