#K78422. Calculate Net Height Change
Calculate Net Height Change
Calculate Net Height Change
You are given m sections of a garden and q observations. Each observation is represented by three integers \(s_i\), \(e_i\), and \(p_i\). For every observation, you add the value \(p_i\) to all sections numbered from \(s_i\) to \(e_i\) (inclusive).
The task is to compute the net height change for each section. Although an integer n is provided in the input, it does not play any role in the computation.
Note: Use a difference-array (or prefix-sum) approach for an efficient solution. All formulas are provided in LaTeX format, for instance:
For each observation, update as follows:
\[ \text{diff}[s_i-1] += p_i \quad \text{and} \quad \text{if } e_i < m: \; \text{diff}[e_i] -= p_i \]Then construct the result by taking the prefix sum of the diff array.
inputFormat
The first line of input contains three space-separated integers: n, m, and q, where n is the number of plants (unused), m is the number of sections, and q is the number of observations.
This is followed by q lines, each containing three integers \(s_i\), \(e_i\), and \(p_i\), representing the start index, end index (inclusive), and the height change respectively.
outputFormat
Output a single line with m space-separated integers. The \(i\)-th integer represents the net height change of section \(i\).
## sample3 5 1
1 2 3
3 3 0 0 0