Sum of Compressed Number for All Subarrays
You are given an array a of size n. The compressed version of an array is defined as replacing the occurrence of consecutive equal integers with the single occurrence.
Example: For a = [1, 1, 2, 2, 1, 1], the compressed version will be [1, 2, 1].
The compressed number of an array is defined as the number of ways to remove some non-empty subsequence of indexes from the initial array to make it compressed. Two ways are considered different if the sequence of indexes deleted from the array was different, the order of removing does not matter.
Calculate the sum of compressed number for all subarrays of the array a. Since the sum may be large, print it modulo 10^9 + 7.
Complete the function sumOfCompressedNumbers in the editor.
sumOfCompressedNumbers has the following parameter:
int a[n]: an array of integers
Returns
int: the sum of compressed number for all the subarrays of the array a modulo 10^9 + 7
1Example 1
a = [6, 7, 3, 6, 6]. The subarrays of a with their respective compressed numbers are as follows:
[6]has compressed number 0 as it is already compressed.- Similarly,
[6, 7],[6, 7, 3],[6, 7, 3, 6]have compressed number 0 as they are already compressed. [6, 7, 3, 6, 6]has compressed number 2 as we can delete either index 4 or index 5 to get compressed version[6, 7, 3, 6].[7],[7, 3],[7, 3, 6]have compressed number 0 as they are already compressed.[7, 3, 6, 6]has compressed number 2.[3],[3, 6]have compressed number 0 as they are already compressed.[3, 6, 6]has compressed number 2.[6]has compressed number 0 as it is already compressed.[6, 6]has compressed number 2.[6]has compressed number 0 as it is already compressed.
a = 8.2Example 2
a = [4, 4]. The subarrays of a with their respective compressed numbers are as follows:
[4]has compressed number 0 as it is already compressed.[4, 4]has compressed number 2 as we can delete either index 1 or index 2 to get compressed version[4].
3Example 3
Constraints
Limits and guarantees your solution can rely on.
1 ≤ t ≤ 101 ≤ n ≤ 10^51 ≤ a[i] ≤ 10^5