E. 愛之行 Walk of Love

Memory limit: 256 MiB Time limit: 1000 ms Input file: stdin Output file: stdout
Problem type: traditional Judging mode: special judge

Description

蘇格拉底、柏拉圖和牛頓談到了愛。

蘇格拉底說︰到田野裡去摘下最特別的花,但你不能回頭,且只有一次機會去採到一朵花。

柏拉圖這樣做了,但過了很久他還是一無所獲地回來。他說他曾經看到過一些很特別的花,但想著會有一些更好的花,所以他只是路過。然而,後來的花並不比之前的好,因此他沒有摘下任何花。

另一方面,牛頓對這個問題建立了一個數學模型。假設有 N 朵花,第 i 朵花的初始價值為正整數 a_i 。有 Q 個事件將按時間順序發生。這些事件有三種不同的類型:

  1. 一個人從第 l 朵花走到第 r 朵花。
    • 這個人逐一經過第 l, l+1, \ldots, r-1, r 朵花。
    • 這個人給每一朵花打分,分數的計算方法是用該花的價值除以他在這次行走中看到的花的當前最大價值(即 score_i = \frac{a_i}{\max(a_l, a_{l+1}, \ldots, a_{i})} )。
    • 牛頓想知道步行的平均得分(即 \frac{score_l + \cdots + score_r}{r - l + 1} )。
  2. x 朵花的價值被設置為 v (即 a_x := v )。
  3. l 朵至第 r 朵花的價值被設置為 v (即 a_l, a_{l + 1}, \ldots, a_r := v )。

你能為牛頓處理這個問題嗎?


Socrates, Plato, and Newton engage in a conversation about Love.

Socrates said, "Go into the field and find the most extraordinary flower. However, you cannot turn back, and you only have one chance to pick a flower."

Plato did so, but he returned empty-handed after a considerable amount of time. He mentioned that he had come across some truly remarkable flowers earlier, but he thought he might find even better ones, so he passed them by. Unfortunately, the subsequent flowers did not surpass the ones he had seen before, resulting in him returning without any flowers.

On the other hand, Newton approached the problem using a mathematical model. Suppose there are N flowers, and the i -th flower is assigned a positive integer value a_i initially. The scenario involves Q events that occur chronologically. These events can be classified into three different types:

  1. A person walks from the l -th flower to the r -th flower.
    • The person passes each flower from l to r one by one.
    • The person assigns a score to each flower, which is calculated by dividing its value by the maximum value among the flowers encountered during the walk (i.e., score_i = \frac{a_i}{\max(a_l, a_{l+1}, \ldots, a_i)} ).
    • Newton wants to determine the average score of the walk, given by \frac{score_l + \cdots + score_r}{r - l + 1} .
  2. The value of the x -th flower is set to v (i.e., a_x := v ).
  3. The values of the flowers from the l -th flower to the r -th flower are set to v (i.e., a_l, a_{l+1}, \ldots, a_r := v ).

Could you assist Newton in solving this problem?

Input

第一行輸入包含兩個整數 N Q

第二行輸入包含 N 個整數。第 i 個整數代表 a_i 的初始值。

接下來的 Q 行輸入中,每一行是對一個事件的描述,按時間順序排列。在第 i 行,第一個整數 t_i 表示第 i 件事件的類型。

  • 如果 t_i = 1 ,那麼之後有兩個整數 l_i, r_i ,表示一個人從第 l_i 朵花走到第 r_i 朵花的事件。
  • 如果 t_i = 2 ,那麼之後有兩個整數 x_i, v_i ,表示第 x_i 朵花的價值被設定為 v_i 的事件。
  • 如果 t_i = 3 ,那麼之後有三個整數 l_i, r_i, v_i ,表示第 l_i 朵至第 r_i 朵花的價值被設定為 v_i 的事件。

The first line of input contains two integers N and Q .

The second line of input consists of N integers. The i -th integer represents the initial value of a_i .

The next Q lines of input each consist of a description of an event, listed chronologically. On the i -th line, the first integer t_i denotes the type of event i .

  • If t_i = 1 , then two integers l_i and r_i follow, indicating the event where a person walks from the l_i -th flower to the r_i -th flower.
  • If t_i = 2 , then two integers x_i and v_i follow, indicating the event where the value of the x_i -th flower is set to v_i .
  • If t_i = 3 , then three integers l_i , r_i , and v_i follow, indicating the event where the value of the flowers from the l_i -th flower to the r_i -th flower is set to v_i .

Output

對於每個事件 1 ,在一行中輸出一個數字,代表步行的平均得分。如果你的答案的絕對或相對誤差不超過 10^{-6} ,將被視為正確。也就是說,假設你的答案是 X ,評測系統的答案是 Y ,如果 \frac{|X-Y|}{\max(1, |Y|)} \le 10^{-6} ,你的答案將被接受。


For each event 1 , output a number in a line, representing the average score of the walk. Your answer is considered correct if its absolute or relative error doesn't exceed 10^{-6} . Namely, let your answer be X , and the judge's be Y , your answer will be accepted if \frac{|X-Y|}{\max(1, |Y|)} \le 10^{-6} .

Sample

Sample 1 input

5 4
3 1 4 1 5
1 2 4
1 3 5
2 3 2
1 2 5

Sample 1 output

0.750000000
0.750000000
0.875000000

Sample 2 input

5 6
6 4 5 2 7
2 1 5
3 2 4 8
1 1 3
1 2 5
3 1 5 6
1 1 5

Sample 2 output

1.000000000
0.968750000
1.000000000

Constraint and hint

對於全部測試數據,滿足: 1 \leq N, Q \leq 10^5 1 \leq A_i \leq 10^9 t_i \in \{1, 2, 3\} 1 \leq l_i \leq r_i \leq N 1 \leq x_i \leq N 1 \leq v_i \leq 10^9 , 保證至少有一次事件 1

子任務 分數 附加限制
1 14 N, Q \leq 1000 , t_i = 1 2
2 37 t_i = 1
3 30 t_i = 1 2
4 19 無附加限制

For all test data, 1 \leq N, Q \leq 10^5 , 1 \leq A_i \leq 10^9 , t_i \in \{1, 2, 3\} , 1 \leq l_i \leq r_i \leq N , 1 \leq x_i \leq N , 1 \leq v_i \leq 10^9 . It is guaranteed that there is at least one event 1 .

Subtask Score Additional Constraints
1 14 N, Q \leq 1000 , t_i = 1 or 2
2 37 t_i = 1
3 30 t_i = 1 or 2
4 19 No additional constraints