#SGM0000056. Truy vấn cập nhật ngẫu nhiên (Random Update Query)
Truy vấn cập nhật ngẫu nhiên (Random Update Query)
Random Update Query
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Each operation chooses a uniformly random position in a range and sets it to . Output every final expected value modulo .
Input
The first line contains . The second line contains . Each of the next lines contains L R X: choose one position uniformly from and set its value to .
Output
Print the final expected values modulo on one line.
Subtasks
-
Subtask 1 (20%): size and operation count at most 30; all other validity conditions are unchanged.
-
Subtask 2 (30%): size and operation count at most 3000; all other validity conditions are unchanged.
-
Subtask 3 (50%): full constraints:
-
-
Examples
Input
3 2
1 2 3
1 3 6
2 2 10
Output
665496238 10 4
Explanation
Each operation becomes an affine update of expectations. After both operations, the expected values modulo 998244353 are 665496238 10 4.