PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SRD0000015. Cập nhật thưa (Sparse update)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Cập nhật thưa (Sparse update)

Sparse update

Source: MarisaOJ

Version: Phuoc Hung OJ Extended

Problem Statement

An integer array AA of length nn is initially filled with zeros. Each of the qq updates specifies integers l,r,dl,r,d, with l≤rl\le r and (r−l)(r-l) divisible by dd.

The update affects only positions

l, l+d, l+2d,…, r.l,\ l+d,\ l+2d,\ldots,\ r.

The increments are not constant: increase AlA_l by 11, Al+dA_{l+d} by 22, and in general, increase Al+tdA_{l+td} by t+1t+1:

$$A_i\leftarrow A_i+\frac{i-l}{d}+1\quad\text{for }i=l+td.$$

All other positions stay unchanged. Compute the complete array after all updates. Updates may overlap and their contributions add together.

Input

The first line contains n,qn,q. Each of the next qq lines contains three integers l r d.

Output

Print the nn integers A1,A2,…,AnA_1,A_2,\ldots,A_n in index order, separated by spaces.

Subtasks

  • Subtask 1 (15 points): 1≤n≤501\le n\le 50; 1≤q≤601\le q\le 60; 1≤l≤r≤n1\le l\le r\le n; 1≤d≤n1\le d\le n; (r−l) mod d=0(r-l)\bmod d=0.
  • Subtask 2 (20 points): 1≤n≤20001\le n\le 2000; 1≤q≤20001\le q\le 2000; 1≤l≤r≤n1\le l\le r\le n; 1≤d≤n1\le d\le n; (r−l) mod d=0(r-l)\bmod d=0.
  • Subtask 3 (25 points): 1≤n≤200001\le n\le 20000; 1≤q≤200001\le q\le 20000; 1≤l≤r≤n1\le l\le r\le n; 1≤d≤n1\le d\le n; (r−l) mod d=0(r-l)\bmod d=0.
  • Subtask 4 (40 points): 1≤n≤1000001\le n\le 100000; 1≤q≤1000001\le q\le 100000; 1≤l≤r≤n1\le l\le r\le n; 1≤d≤n1\le d\le n; (r−l) mod d=0(r-l)\bmod d=0.

Examples

Input

5 2
1 5 2
2 2 3

Output

1 1 2 0 3

Explanation

Update 1 5 2 touches positions 1,3,51,3,5 and adds 1,2,31,2,3, giving [1,0,2,0,3][1,0,2,0,3]. Update 2 2 3 touches only position 22 and adds 11. Thus the final array is [1,1,2,0,3][1,1,2,0,3]. Even though d=3d=3 in the second update, l=rl=r means there is only one increment.