#C5910. Review Manager Operations

    ID: 49612 Type: Default 1000ms 256MiB

Review Manager Operations

Review Manager Operations

You are required to implement a ReviewManager that maintains a list of integer review scores and supports several operations. Initially, you are given a list of review scores. Then, a series of commands will be provided.

The supported operations are:

  • ADD s: Add a new review with score \(s\).
  • UPDATE idx s: Update the review at index \(idx\) (0-indexed) to have the new score \(s\).
  • DELETE idx: Delete the review at index \(idx\) from the list.
  • AVERAGE: Calculate and output the average score of all reviews, rounded to two decimal places. If there are no reviews, output \(0.00\).
  • COUNT s: Output the number of reviews that have the exact score \(s\).

You must process the commands sequentially and output the result of any AVERAGE and COUNT operation to standard output.

inputFormat

The input is read from stdin and formatted as follows:

  1. The first line contains an integer \(N\), the number of initial review scores.
  2. The second line contains \(N\) space-separated integers representing the initial review scores.
  3. The third line contains an integer \(Q\), the number of operations.
  4. The next \(Q\) lines each contain one command. Each command is one of the following formats:
    • ADD s
    • UPDATE idx s
    • DELETE idx
    • AVERAGE
    • COUNT s

All numbers are integers. Indexing is 0-indexed.

outputFormat

For each AVERAGE or COUNT command, output the result on a new line to stdout. The average score must be rounded to two decimal places.

## sample
3
1 2 3
3
UPDATE 1 5
AVERAGE
COUNT 5
3.00

1

</p>