#K12496. Apply Update Operations on an Array
Apply Update Operations on an Array
Apply Update Operations on an Array
You are given an initial array of integers and a sequence of update operations. Each update operation is represented by three integers l, r, and v, which means that you should set all elements of the array with indices from l to r (inclusive) to the value v.
Input format: The first line contains an integer n, the size of the array. The second line contains n space-separated integers — the initial array. The third line contains an integer m, the number of operations. Then, m lines follow, each containing three integers l, r, and v representing an update operation.
Output format: After applying all the update operations in the given order, output the final state of the array as a list of space-separated integers.
Note: All indices are 0-based.
The operations are applied sequentially, and later operations may override the effect of earlier operations.
Mathematically, if the original array is \(A = [a_0, a_1, \dots, a_{n-1}]\) and an operation is \([l, r, v]\), then for every index \(i\) such that \(l \leq i \leq r\), the new value becomes \(A[i] = v\). The final array is the result of applying all such operations in order.
inputFormat
The input is read from stdin and has the following format:
- The first line contains an integer n — the number of elements in the array.
- The second line contains n space-separated integers representing the initial array.
- The third line contains an integer m — the number of update operations.
- Each of the next m lines contains three integers l, r, and v describing an operation to set every array element between indices l and r (inclusive) to v.
outputFormat
Output the final state of the array as a single line with the array elements separated by spaces. The output is printed to stdout.
## sample5
0 0 0 0 0
3
0 1 10
2 4 5
1 3 20
10 20 20 20 5
</p>