#P12013. Dynamic Range Average Query
Dynamic Range Average Query
Dynamic Range Average Query
You are given a sequence \(a_1, a_2, \dots, a_n\) of length \(n\) and you need to process \(m\) operations. There are two types of operations:
- Update Operation: Given three integers \(l\), \(r\), and \(x\), add \(x\) to each element in the subarray \(a_l, a_{l+1}, \dots, a_r\). That is, perform \(a_i = a_i + x\) for every \(l \le i \le r\).
- Query Operation: Given two integers \(l\) and \(r\), compute \[ \max_{l \le L < R \le r} \frac{\sum_{i=L}^R a_i}{R-L+1}, \] which means you need to find the maximum average of any contiguous subarray (of length at least 2) within the interval \([l, r]\).
You should output the answer for each query operation with a precision of 6 decimal places.
inputFormat
The first line contains two integers \(n\) and \(m\) \( (2 \le n, 1 \le m)\), representing the length of the sequence and the number of operations respectively.
The second line contains \(n\) integers \(a_1, a_2, \dots, a_n\) representing the initial sequence.
Each of the following \(m\) lines describes an operation in one of the following formats:
- "1 l r x" — an update operation (add \(x\) to all elements in the subarray \(a_l \ldots a_r\)).
- "2 l r" — a query operation (output the maximum average of any subarray of length at least 2 inside indices \(l\) to \(r\)).
outputFormat
For each query operation (operation of type 2), output a single line containing the maximum average value, formatted to 6 decimal places.
sample
5 4
1 2 3 4 5
2 1 5
1 1 3 1
2 1 5
2 2 4
4.500000
4.500000
4.000000
</p>