#C7739. Library Operations Manager
Library Operations Manager
Library Operations Manager
This problem simulates a simple library management system. You are given N books initially available for loan and M operations. Each operation is either a loan or a return which affects the status of a book. For a loan operation, if the book is available, it becomes loaned out and the operation returns Success
; if it is already loaned, it returns Failure
. Similarly, for a return operation, if the book is currently loaned, it becomes available again and returns Success
; otherwise, it returns Failure
.
The operations are executed sequentially. Your task is to simulate these operations and output the result of each operation on a new line.
Formally, let the state of the books be represented by an array book_status where book_status[i] = 0 means the i-th book is available, and book_status[i] = 1 means it is loaned. For an operation given by an instruction op and a book index x:
if op = loan, then
\(book\_status[x] = 0 \to book\_status[x] = 1\) and output \(Success\), otherwise output \(Failure\).
if op = return, then
\(book\_status[x] = 1 \to book\_status[x] = 0\) and output \(Success\), otherwise output \(Failure\).
inputFormat
The first line contains two integers N and M (1 \leq N, M \leq 10^5), where N is the number of books and M is the number of operations.
The next M lines each contain an operation in the format: "loan x" or "return x", where x is the book number (1-indexed).
outputFormat
Output M lines, each line being either Success
or Failure
corresponding to the result of each operation.
3 5
loan 1
loan 2
loan 1
return 2
return 1
Success
Success
Failure
Success
Success
</p>