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

Bài tập thuộc lộ trình

2 lộ trình

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 AA of length nn, indexed from 00 to n−1n-1. Initially, every element is 00.

There are mm update operations. Operation ii is described by li,ri,dil_i,r_i,d_i and adds did_i to each element at indices li,li+1,…,ril_i,l_i+1,\ldots,r_i, 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 00.

Input

  • The first line contains integers n,mn,m: the array length and the number of operations.
  • Each of the next mm lines contains integers li,ri,dil_i,r_i,d_i specifying the inclusive interval and its increment. Array positions are zero-based.

Output

Print exactly nn space-separated integers on one line: A0,A1,…,An−1A_0,A_1,\ldots,A_{n-1} after all operations.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; 0≤m≤200\le m\le 20; 0≤li≤ri<n0\le l_i\le r_i<n and −1000≤di≤1000-1000\le d_i\le1000 in every update.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; 0≤m≤20000\le m\le 2000; 0≤li≤ri<n0\le l_i\le r_i<n and −1000≤di≤1000-1000\le d_i\le1000 in every update.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; 0≤m≤100000\le m\le 10000; 0≤li≤ri<n0\le l_i\le r_i<n and −1000≤di≤1000-1000\le d_i\le1000 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 [0,0,0,0,0][0,0,0,0,0]:

  • Add 22 to [1,3][1,3]: [0,2,2,2,0][0,2,2,2,0].
  • Add 33 to [2,4][2,4]: [0,2,5,5,3][0,2,5,5,3].
  • Add −2-2 to [0,2][0,2]: [−2,0,3,5,3][-2,0,3,5,3].

The requested output is the entire final array: -2 0 3 5 3.