QOJ.ac

QOJ

حد الوقت: 3 s حد الذاكرة: 256 MB مجموع النقاط: 100

#5223. Segment Tree

الإحصائيات

Little Yuuka encountered a problem: there is a sequence $a_1, a_2, \dots, a_n$ and $q$ operations. Each operation changes the numbers in a range to the maximum value within that range. The question is what each number becomes at the end. Little Yuuka quickly solved this problem using a segment tree.

Being a wise girl, Little Yuuka wondered: if the operations are random, i.e., in each of the $q$ operations, we choose a range $[l, r]$ ($1 \le l \le r \le n$) uniformly at random (note that there are $\frac{n(n+1)}{2}$ such ranges) and change the numbers in this range to the maximum value within it, what is the expected value of each number at the end?

Little Yuuka loves randomness, so the input sequence she provides is also random (see Constraints for the generation method).

For each number, output its expected value multiplied by $\left(\frac{n(n+1)}{2}\right)^q$ modulo $10^9 + 7$.

Input

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

The next line contains $n$ non-negative integers $a_1, a_2, \dots, a_n$.

Output

Output a single line containing $n$ integers, representing the answer for each number.

Examples

Input 1

5 5
1 5 2 3 4

Output 1

3152671 3796875 3692207 3623487 3515626

Input 2

See segment/segment_ex1.in in the contestant directory.

Output 2

See segment/segment_ex1.ans in the contestant directory.

Note

Sample inputs and outputs 1 and 2 do not satisfy the generation method described in the constraints.

Input 3

See segment/segment_ex2.in in the contestant directory.

Output 3

See segment/segment_ex2.ans in the contestant directory.

Constraints

For all test data, it is guaranteed that the values in the sequence do not exceed $10^9$, i.e., $a_i \le 10^9$, and each number is a random integer between $0$ and $10^9$.

Each test case satisfies the following constraints:

Test Case $n$ $q$ Constraints
1 $\le 5$ $\le 5$ None
2 $\le 8$ $\le 400$ None
3 $\le 12$ $\le 400$ None
4 $\le 30$ $\le 400$ None
5 $\le 50$ $\le 400$ None
6 $\le 100$ $\le 400$ None
7 $\le 100$ $\le 400$ None
8 $\le 100$ $\le 400$ None
9 $\le 400$ $\le 400$ None
10 $\le 400$ $\le 400$ None

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.