#P2122. 还教室

还教室

Description

During the nn days when rental requests were accepted, on day ii there are aia_i classrooms remaining. As the person in charge of the university classroom rental service, you need to perform mm operations of the following three types:

  1. From day ll to day rr, dd classrooms are returned each day.
  2. Query the average number of classrooms from day ll to day rr.
  3. Query the variance of the number of classrooms from day ll to day rr.

Input Format

The first line contains two positive integers nn and mm, where nn is the number of days and mm is the number of operations.

The next line contains nn integers; the ii-th integer indicates that on day ii the number of remaining classrooms is aia_i.

The next mm lines: each line starts with the operation code (only 11, 22, or 33), followed by two positive integers ll and rr. If the operation code is 11, then an additional positive integer dd follows.

Output Format

For each operation of type 22 and type 33, output the answer as a reduced fraction (the numerator and denominator are coprime). In particular, if the answer is 00, output 0/1\verb!0/1!.

5 4
1 2 3 4 5
1 1 2 3
2 2 4
3 2 4
3 1 5
4/1
2/3
14/25

Hint

For all testdata, 1lrn1051 \leq l \leq r \leq n \leq 10^5, m105m \leq 10^5, 0ai100 \leq a_i \leq 10, 1d31 \leq d \leq 3, and the number of type 11 operations does not exceed 10%10\%.

Note: The small ranges of aia_i and dd, and the small number of type 11 operations, are intended to ensure that the numerator of the answer will not be large, preventing overflow beyond the 6464-bit integer range; this is unrelated to the intended solution.

Translated by ChatGPT 5