#C14825. Cumulative Product Calculation with Range
Cumulative Product Calculation with Range
Cumulative Product Calculation with Range
Given a list of integers and an optional subarray range [start, end), compute the cumulative product for the elements in the given range while leaving the other elements unchanged.
The cumulative product for an index i in the range is defined as:
$$result[i] = \prod_{j=start}^{i} a_j$$
For indices outside the specified range, the original value is retained. If the subarray range is not specified, the entire list should be processed.
Note: In the input, if the two integers representing start and end are provided as -1, it indicates that the default range (the entire list) should be used.
inputFormat
The input is taken from stdin and consists of three lines:
- An integer
n
representing the number of elements in the list. n
space-separated integers representing the list.- Two space-separated integers representing
start
andend
. If both are -1, then the entire list is processed.
It is guaranteed that the provided input will be valid.
outputFormat
Output the modified list to stdout as a single line of space-separated integers, where the elements in the specified range have been replaced by their cumulative product, and the others remain unchanged.
## sample4
1 2 3 4
-1 -1
1 2 6 24