PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FT0000240. Cộng giá trị trên các đoạn (Range Addition)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Cộng giá trị trên các đoạn (Range Addition)
Range Addition
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
You have an integer array of length , indexed from to . Initially, every element is .
There are update operations. Operation is described by and adds to each element at indices , inclusive. The increment may be negative, zero, or positive.
After all operations have been applied in their given order, output the entire resulting array in ascending index order. With no operations, every array element remains .
Input
- The first line contains integers : the array length and the number of operations.
- Each of the next lines contains integers specifying the inclusive interval and its increment. Array positions are zero-based.
Output
Print exactly space-separated integers on one line: after all operations.
Subtasks
- Subtask 1 (20 points): ; ; and in every update.
- Subtask 2 (30 points): ; ; and in every update.
- Subtask 3 (50 points): ; ; and in every update.
Examples
Input
5 3
1 3 2
2 4 3
0 2 -2
Output
-2 0 3 5 3
Explanation
Starting from :
- Add to : .
- Add to : .
- Add to : .
The requested output is the entire final array: -2 0 3 5 3.