#K52232. Bike Sharing Management

    ID: 29264 Type: Default 1000ms 256MiB

Bike Sharing Management

Bike Sharing Management

You are responsible for managing a bike sharing system that consists of \( n \) stations. Each station starts with an initial number of bikes. You will receive \( m \) operations, and you need to process them in order. The operations can be one of the following:

  • Rent x: Rent a bike from station \( x \).
  • Return x: Return a bike to station \( x \).
  • Query x: Query the current number of bikes at station \( x \).

Note that the station numbering is 1-indexed, meaning that stations are numbered from 1 to \( n \). When processing an operation:

  • If it is a "Rent" operation, decrement the bike count at station \( x \) by 1.
  • If it is a "Return" operation, increment the bike count at station \( x \) by 1.
  • If it is a "Query" operation, output the current bike count at station \( x \).

Implement the solution so that it reads the input from standard input (stdin) and writes the output to standard output (stdout). Each query result should be printed on a separate line.

The update rule for each station can be expressed as:

\( \text{new_count} = \text{old_count} \pm 1 \)

inputFormat

The input is received from standard input (stdin) in the following format:

  1. The first line contains an integer ( n ), the number of bike stations.
  2. The second line contains ( n ) integers separated by spaces, where the ( i^{th} ) integer represents the initial number of bikes at station ( i ).
  3. The third line contains an integer ( m ), the number of operations.
  4. The next ( m ) lines each contain a string describing an operation, which is one of the formats: "Rent x", "Return x", or "Query x" (with ( x ) being the station number).

outputFormat

For every "Query" operation, print the number of bikes available at the specified station. Each result should be printed on a new line.## sample

5
8 2 5 3 10
7
Rent 3
Query 3
Return 1
Query 1
Rent 2
Query 2
Query 5
4

9 1 10

</p>