#K76037. Range Update Queries

    ID: 34553 Type: Default 1000ms 256MiB

Range Update Queries

Range Update Queries

You are given an array of n integers and m queries. Each query consists of three integers, l, r, and v. For every query, you must add v to each element of the array whose index is in the range [l, r] (1-indexed).

The update for each query can be represented using the difference array technique. If we denote the difference array by diff, the update operations can be mathematically described as:

$$ diff[l-1] \mathrel{+}= v \quad \text{and} \quad diff[r] \mathrel{-}= v \quad \text{if } r < n. $$

After processing all queries, compute the cumulative sum of the difference array and add it to the original array to get the resultant array.

inputFormat

The input is read from stdin and has the following format:

  • The first line contains two integers n and m, representing the size of the array and the number of queries, respectively.
  • The second line contains n space-separated integers representing the initial array.
  • The next m lines each contain three space-separated integers: l, r, and v, where l and r denote the starting and ending indices (1-indexed) of the query range, and v is the value to be added.

outputFormat

Output the final updated array as a single line of n space-separated integers. The output should be written to stdout.

## sample
5 3
1 2 3 4 5
1 3 2
2 5 3
3 4 -1
3 7 7 6 8