Segment tree range assign

Write codeHard40 min

Your task

Implement a segment tree over an integer array supporting two operations applied in order: ['assign', l, r, v] sets every element in the inclusive index range [l, r] to v, and ['sum', l, r] returns the sum over [l, r]. Given the initial array and the operation list, return the list of answers to the 'sum' queries in order. Use lazy propagation so each operation is O(log n).

Examples

range_assign_sum(arr: list[int], ops: list[list]) -> list[int]
Example 1
Inputrange_assign_sum([1, 2, 3, 4, 5], [["sum", 0, 4], ["assign", 1, 3, 10], ["sum", 0, 4], ["sum", 2, 2]])
Output[15, 36, 10]