#P3352. [ZJOI2016] 线段树
[ZJOI2016] 线段树
Description
Little Yuuka encountered a problem: given a sequence and operations. In each operation, choose an interval and set all numbers in that interval to the maximum value within the interval. After all operations, what is the final value of each number? Little Yuuka quickly solved this using a segment tree.
Then the wise Little Yuuka wondered: what if the operations are random? That is, in each of the operations, we choose an interval uniformly at random among all intervals with , and then set all numbers in that interval to the interval maximum (note that there are such intervals). What is the expected final value of each number?
Little Yuuka loves randomness, so the input sequence is also random (see Constraints and conventions in the Hint).
For each position, output its expectation multiplied by , then taken modulo .
Input Format
The first line contains two positive integers , the number of elements in the sequence and the number of operations.
The second line contains non-negative integers .
Output Format
Output a single line containing integers, the answer for each position.
5 5
1 5 2 3 4
3152671 3796875 3692207 3623487 3515626
Hint
For all testdata, the values in the sequence are at most , and each number is a random integer between and .
| Test point ID | ||
|---|---|---|
| 1 | ||
| 2 | ||
| 3 | ||
| 4 | ||
| 5 | ||
| 6 | ||
| 7 | ||
| 8 | ||
| 9 | ||
| 10 | ||
Translated by ChatGPT 5
京公网安备 11011102002149号