#K73802. Array Operations and Sum Computation
Array Operations and Sum Computation
Array Operations and Sum Computation
You are given an integer array and a sequence of operations. In each operation, you are given three integers \(l\), \(r\), and \(val\). For every index \(i\) with \(l \leq i \leq r\) (1-indexed), you need to increase the element \(a_i\) by \(val\). After each operation, compute the sum of the array, i.e. \(S = \sum_{i=1}^{n} a_i\).
You must perform the operations sequentially, updating the array in-place. Print the sum of the array after each operation.
inputFormat
The input is given via standard input (stdin). The first line contains two integers (n) and (q), where (n) ((1 \leq n \leq 10^5)) is the number of elements in the array and (q) ((1 \leq q \leq 10^5)) is the number of operations. The second line contains (n) space-separated integers describing the initial array. Each of the next (q) lines contains three integers (l), (r), and (val) (with 1-based indexing), indicating that you must add (val) to each element of the array from index (l) to index (r) (inclusive).
outputFormat
Output via standard output (stdout). Print (q) lines. Each line should contain a single integer representing the sum of the array after performing the corresponding operation.## sample
5 3
1 2 3 4 5
1 3 10
2 5 -3
3 3 5
45
33
38
</p>