#C5171. Library Loan Query Processing

    ID: 48791 Type: Default 1000ms 256MiB

Library Loan Query Processing

Library Loan Query Processing

You are given information about book loan records in a library. The library maintains records of which books are loaned to which users. For each loan record, a book and a user are identified by their corresponding integer IDs.

You will be given:

  • An integer \(N\) representing the total number of books.
  • An integer \(M\) representing the total number of loan records.
  • An integer \(Q\) representing the number of queries.
  • \(M\) lines each containing two integers \(B\) and \(U\) indicating that book \(B\) was loaned to user \(U\).
  • \(Q\) queries, each either in the form "Book B" or "User U".

For a query of the form Book B, output the sorted list of user IDs (separated by a single space) who have borrowed book \(B\). For a query of the form User U, output the sorted list of book IDs borrowed by user \(U\). If there are no records for the requested book or user, output "None".

The sorting is in increasing numerical order. Note that there may be multiple loans associated with the same book or user.

inputFormat

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

N M Q
B₁ U₁
B₂ U₂
... (M lines in total)
query₁
query₂
... (Q lines in total)

Where:

  • The first line contains three integers: \(N\) (number of books), \(M\) (number of loan records), and \(Q\) (number of queries).
  • The next \(M\) lines each contain two integers \(B\) and \(U\) describing that book \(B\) was loaned to user \(U\).
  • The following \(Q\) lines each contain a query either in the form "Book B" or "User U".

outputFormat

For each query, output a single line:

  • If the query is "Book B", print the sorted list of user IDs that have borrowed book \(B\), separated by a space. If there is no such record, output "None".
  • If the query is "User U", print the sorted list of book IDs borrowed by user \(U\), separated by a space. If there is no such record, output "None".

Output is written to standard output.

## sample
5 6 4
1 101
2 102
1 103
3 101
4 104
5 105
Book 1
User 101
Book 6
User 102
101 103

1 3 None 2

</p>