#K11451. Calculate Final Scores
Calculate Final Scores
Calculate Final Scores
You are given n participants with their initial scores and m operations. Each operation is described by three integers l, r and v. For each operation, you need to add v to the scores of all participants with indices from l to r (inclusive).
The update operation can be mathematically described using the following formula:
$$score_i = score_i + \sum_{\substack{(l,r,v)\\ l \le i \le r}} v $$Your task is to compute the final scores after applying all the operations sequentially.
inputFormat
The input is provided via standard input (stdin
) as follows:
- The first line contains two integers
n
andm
wheren
is the number of participants andm
is the number of operations. - The second line contains
n
space-separated integers representing the initial scores of the participants. - The next
m
lines each contain three space-separated integersl
,r
, andv
representing an operation that addsv
to all scores from participantl
tor
(1-indexed).
outputFormat
Output a single line to standard output (stdout
) containing n
space-separated integers representing the final scores of the participants after performing all the operations.
5 3
1 2 3 4 5
1 3 10
2 5 -5
1 5 3
14 10 11 2 3