#K1051. Library Operations Simulation

    ID: 23262 Type: Default 1000ms 256MiB

Library Operations Simulation

Library Operations Simulation

You are given a simulation of a library system. There are N library members and M books. Initially, no member has borrowed any book. The system must process a sequence of operations. Each operation is one of the following types:

  • BORROW A B: Member A borrows book B if it is not already borrowed.
  • RETURN A B: Member A returns book B if he/she had borrowed it.
  • CHECK A B: Check if member A currently has book B. Print YES if so, otherwise NO.
  • MEMBER-BOOKS A: List in increasing order all book IDs currently borrowed by member A separated by a single space. If none, print NONE.
  • BOOK-MEMBER B: Display the member ID who has borrowed book B. If the book is not borrowed, print NONE.

It is guaranteed that the operations are valid for the simulation. The final output should contain the results for the operations CHECK, MEMBER-BOOKS, and BOOK-MEMBER only, each printed on a separate line in the order they appear in the input.

Note: If a book is attempted to be borrowed while it is already on loan, nothing will change in the system.

For any equations mentioned in the problem statement, use LaTeX format. For example, the number of members is given by $N$ and the number of books by $M$.

inputFormat

The input is given from standard input and has the following format:

N M
Q
operation_1
operation_2
... 
operation_Q

Where:

  • N is the number of library members.
  • M is the number of books.
  • Q is the total number of operations.
  • Each operation_i is one of the operations described above.

outputFormat

For each operation that produces an output (CHECK, MEMBER-BOOKS, and BOOK-MEMBER), print the result on a new line to standard output.

## sample
3 5
9
BORROW 1 3
BORROW 2 4
CHECK 1 3
CHECK 2 3
MEMBER-BOOKS 1
BOOK-MEMBER 4
RETURN 1 3
BOOK-MEMBER 3
MEMBER-BOOKS 1
YES

NO 3 2 NONE NONE

</p>