#P3352. [ZJOI2016] 线段树

[ZJOI2016] 线段树

Description

Little Yuuka encountered a problem: given a sequence a1,a2,,ana_1, a_2, \ldots, a_n and qq operations. In each operation, choose an interval [l,r][l, r] 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 qq operations, we choose an interval [l,r][l, r] uniformly at random among all intervals with 1lrn1 \leq l \leq r \leq n, and then set all numbers in that interval to the interval maximum (note that there are n(n+1)2\frac{n(n+1)}{2} 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 (n(n+1)2)q\left(\frac{n(n+1)}{2} \right)^q, then taken modulo 109+710^9+7.

Input Format

The first line contains two positive integers n,qn, q, the number of elements in the sequence and the number of operations.

The second line contains nn non-negative integers a1,a2,,ana_1, a_2, \ldots, a_n.

Output Format

Output a single line containing nn 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 10910^9, and each number is a random integer between 00 and 10910^9.

Test point ID nn qq
1 5\leq 5
2 8\leq 8 400\leq 400
3 12\leq 12
4 30\leq 30
5 50\leq 50
6 100\leq 100
7
8 400\leq 400
9
10

Translated by ChatGPT 5