Question 19
The memory of Bob's computer contains two interesting things: an array of integers and a virus. Each midnight the virus becomes active. It takes each array in memory and replaces it with a bunch of new arrays: one for each contiguous subarray of the original array.
For example, if today the memory contains a single array (1,2,1,3), tomorrow it will contain the following arrays: (1), (2), (1), (3), (1,2), (2, 1), (1, 3), (1,2,1), (2, 1,3), (1,2, 1, 3).
As another example, if today the memory contains a single array {(7,7)},tomorrow it will contain the following arrays: {(7), (7), (7,7)}, and the day after tomorrow it will contain the following arrays: {(7), (7), (7), (7), (7,7)}, and so on.
You are given Bob's original array A and the number of days D. Let be the sum of all elements of all arrays that will be in the memory of Bob's computer after D days. Our goal is to calculate . You may assume that the memory of Bob's computer is sufficiently large to accommodate all the arrays.
Based on the above data, answer the given subquestions.
Suppose we store, for every pair of indices , the number of times the subarray (i, j inclusive) appears in the memory of Bob's computer on a particular day. Specifically, let denote the number of occurrences of in the set of arrays generated after days. Then: