#K86192. Show Ratings Management

    ID: 36810 Type: Default 1000ms 256MiB

Show Ratings Management

Show Ratings Management

You are given a list of shows with their user ratings. There are two types of operations (queries) you can perform on these ratings:

  • Update the rating of a show.
  • Query the average rating of a range of shows.

For an update query, you are provided with type 1, an index i and a new rating j. For a range query, the query type is 2, and you are provided with two indices i and j, and you need to compute the average of the ratings from the ith show to the jth show (both inclusive). The average must be output with exactly two decimal places.

Note: The indices are 1-based.

You are required to handle multiple test cases from the standard input.

The formula for the average of a sequence of numbers \(a_i\) from index \(i\) to \(j\) is given by:

[ \text{average} = \frac{\sum_{k=i}^{j} a_k}{j-i+1} ]

Your task is to update and query ratings as described, and output the query results to the standard output.

inputFormat

The input begins with an integer T (\(1 \le T \le 10\)) representing the number of test cases. Each test case is described as follows:

  1. The first line contains two integers \(N\) and \(Q\) (\(1 \le N, Q \le 10^5\)), representing the number of shows and the number of queries respectively.
  2. The second line contains \(N\) space-separated integers, representing the initial ratings of the shows.
  3. The next \(Q\) lines each contain three integers type i j where:
    • if type == 1: update the rating of the ith show to j.
    • if type == 2: compute the average rating for shows in the range \([i, j]\).

It is guaranteed that the indices are valid and all ratings are integers.

outputFormat

For each query of type 2 in every test case, output the computed average rating on a new line, formatted to exactly two decimal places.

## sample
1
5 3
10 20 30 40 50
1 3 35
2 2 4
2 1 5
31.67

31.00

</p>