TLE '15 P5 - Prefix Sum Array

View as PDF

Submit solution

Points: 15 (partial)
Time limit: 1.0s
Memory limit: 256M

Problem type

Fax McClad, Croneria's most courageous bounty hunter, often has weird dreams in his sleep. Sometimes, he dreams about his past experiences, and at other times, he has nightmares about problem statements that have no relation to the actual problem.

One night, Fax had a very, very bizarre dream about d:

d received an array of length N (1 \le N \le 2\,000) with elements numbered from 1 \ldots N, and he performed the sum operation on it.

The sum operation takes in an array A and returns an array B. Array B has these two important properties:

  1. Array A and array B are equal in length.
  2. For all elements B[k], the element satisfies B[k] = A[1]+A[2]+\ldots+A[k]

Unimpressed with the result, d fed the result back in to the sum operation repeatedly, performing the operation M (2 \le M \le 10^9) times in total. At this point, d

Suddenly, Fax wakes up! Disturbed by the abstract dream, he asks you to help solve the problem so he can focus on his bounty hunting.


Subtask 1 [20%]

Tasks satisfy the constraint N \times M \le 10^6.

Subtask 2 [60%]

Tasks satisfy the constraint N \le 100.

Subtask 3 [20%]

No additional constraints.

Input Specification

The first line will contain N, the number of elements in the array.

The next line will contain the elements A[1],A[2],\ldots,A[N], (0 \leq A[i] \leq 10^9+6), each separated by a space.

The final line of input will contain M, the number of times the sum operation is performed.

Output Specification

The array after performing M sum operations on the given array.

Each element should be outputted mod 10^9+7 and elements should be separated by a single space.

Sample Input

4 2 8 1 1

Sample Output

4 10 24 39 55

Explanation for Sample Output

After one sum operation, the array is changed to:

4 6 14 15 16

After the second sum operation, the array is changed to:

4 10 24 39 55


  • 8
    septence123  commented on Feb. 24, 2017, 9:54 p.m.

    So I submitted in pypy2 and got everything correct except for the last test case of the last batch is there any further optimizations i can implement?