Triangular Range Increments
Problem statement
You are given initial values and queries [i,v], using zero-based indices.
Each query adds max(v - abs(j-i), 0) to every valid position j. The contribution decreases by one per step away from i; each side stops at its boundary or at a zero contribution.
Return the final array after all queries. Use signed 64-bit values for the result.
Function
applyTriangularUpdates(values: int[], queries: int[][]) → long[]Examples
Example 1
values = [0,0,0,0,0,0,0,0,0]queries = [[3,5]]return = [2,3,4,5,4,3,2,1,0]The corrected source pattern adds [2,3,4,5,4,3,2,1,0].
Example 2
values = [2,0,1]queries = [[0,2],[2,3]]return = [5,3,4]Both triangular contributions are added independently and clipped at the array boundaries.
Constraints
1 <= values.length <= 10^50 <= queries.length <= 10^50 <= values[j] <= 10^9- Each query contains
[i,v], with0 <= i < values.lengthand1 <= v <= 10^9.