#K96107. Movie Theater Ticketing System

    ID: 39013 Type: Default 1000ms 256MiB

Movie Theater Ticketing System

Movie Theater Ticketing System

You are tasked with designing a simple ticketing system for a movie theater. The theater consists of r rows and c columns of seats. Each seat is assigned a unique number in row-major order starting at 0 (i.e. the top‐left seat is numbered 0, the one to its right is 1, and so on).

The system accepts several commands:

  • A x: Reserve seat number \(x\). If the seat is already reserved, do nothing.
  • C x: Cancel the reservation for seat \(x\). If the seat is not reserved, do nothing.
  • Q x: Query the status of seat \(x\). Print "Reserved" if the seat is reserved; otherwise, print "Available".

The input consists of multiple datasets. Each dataset starts with a line containing two integers \(r\) and \(c\) representing the number of rows and columns respectively. This is followed by a line with an integer \(n\), the number of commands for that dataset. The next \(n\) lines contain commands. A dataset with \(r = 0\) and \(c = 0\) indicates the end of input.

For each dataset, output the results of every query command (Q). Separate the outputs of different datasets with an empty line.

inputFormat

The input is provided via standard input (stdin) with multiple datasets. For each dataset:

  1. The first line contains two integers \(r\) and \(c\) separated by a space. \(r\) and \(c\) denote the number of rows and columns respectively.
  2. The next line contains an integer \(n\) indicating the number of commands.
  3. Each of the following \(n\) lines contains a command in one of the following formats: "A x", "C x", or "Q x", where x is an integer representing the seat number.
  4. An input line with "0 0" signals the end of all datasets.

outputFormat

For each dataset, print the result of each query command (Q) on a separate line. After each dataset (except the last one), output an empty line to separate the datasets.

## sample
3 5
6
A 2
A 5
Q 2
C 2
Q 2
Q 5
2 2
3
Q 2
A 2
Q 2
0 0
Reserved

Available Reserved

Available Reserved

</p>