公式

F - Random Update Query 解説 by en_translator


The expected value \(E_i\) of each \(A_i\) before the operations is obviously \(A_i\) itself given in the input. By the operations, the expected value \(E_i\) of each \(A_i\) is gradually updated.

Specifically, an element \(A_p\) in the segment \([L_i, R_i]\) affected by the \(i\)-th operation is updated to \(X_i\) with probability of \(\frac{1}{\lambda_i}\) and remains the same with probability \(\frac{\lambda_i-1}{\lambda_i}\) (where \(\lambda_i \coloneqq R_i - L_i + 1\)). By this operation, for each element \(A_p\) in the segment, the resulting expected value \(E_p'\) is expressed using the previous value \(E_p\) as \(E'_p = \frac{\lambda_i-1}{\lambda_i}x + \frac{1}{\lambda_i}E_p\).

Therefore, this problem can be solved by maintaining \(E = (E_1, E_2, \ldots, E_N)\). Specifically, initialize each \(E_i\) with the input value \(A_i\), perform the following operation for each \(i = 1, 2, \ldots, M\) in this order, and print the resulting \(E\).

For each element in the segment \([L_i, R_i]\), replace its value \(x\) with \(\frac{\lambda_i-1}{\lambda_i}x + \frac{1}{\lambda_i}X_i\).

This can be achieved fast by using lazy-propagation segment tree (lazy_segtree in AtCoder Library).

投稿日時:
最終更新: