#P2122. Classroom Borrowing and Return Analysis

    ID: 15404 Type: Default 1000ms 256MiB

Classroom Borrowing and Return Analysis

Classroom Borrowing and Return Analysis

You are given n days of classroom borrowing requests. On day \(i\), there are \(a_i\) classrooms available. As the administrator responsible for the university classroom lending service, you need to handle m operations. There are three types of operations:

  1. Return Operation: For every day from \(l\) to \(r\) (inclusive), \(d\) classrooms are returned (i.e. the available count increases by \(d\)).
  2. Average Query: Query the average number of classrooms available from day \(l\) to day \(r\) (inclusive).
  3. Variance Query: Query the variance of the number of classrooms available from day \(l\) to day \(r\) (inclusive). The variance is defined as \[ \text{Var} = \frac{1}{r-l+1}\sum_{i=l}^{r}(a_i - \overline{a})^2, \] where \(\overline{a}\) is the average of \(a_l, a_{l+1}, \dots, a_r\).

The operations are given in order and you should process them sequentially. Note that update operations (type 1) modify the values for subsequent queries.

inputFormat

The first line contains two integers \(n\) and \(m\): the number of days and the number of operations, respectively.

The second line contains \(n\) integers \(a_1, a_2, \ldots, a_n\) representing the initial number of available classrooms for each day.

The following \(m\) lines each describe an operation. An operation is in one of the following formats:

  • For a return operation (type 1): 1 l r d — for all days from \(l\) to \(r\), add \(d\) to \(a_i\).
  • For an average query (type 2): 2 l r
  • For a variance query (type 3): 3 l r

outputFormat

For each query operation (types 2 and 3), output a single real number on a new line:

  • For an average query (type 2), output the average of the classrooms available in the given range.
  • For a variance query (type 3), output the variance of the classrooms available in the given range.

The answers will be accepted if they have an absolute or relative error of at most \(10^{-6}\).

sample

5 5
10 20 30 40 50
2 2 4
1 3 5 5
3 1 5
2 1 3
3 4 5
30.0

266.0 21.666666666666668 25.0

</p>