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

#PS0000273. Cộng hàm tuyến tính trên đoạn (Linear Function Range Updates)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Cộng hàm tuyến tính trên đoạn (Linear Function Range Updates)

Linear Function Range Updates

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

An array AA of length nn is initially zero and indexed from 1. Each update (l,r,u,v)(l,r,u,v) adds u⋅i+vu\cdot i+v to AiA_i for all l≤i≤rl\le i\le r. Here ii is the absolute array index, not an offset from ll. Print the final array.

Input

First line: n,qn,q. Next qq lines: l,r,u,vl,r,u,v.

Output

Print nn integers on one line.

Subtasks

  • Subtask 1 (20 points): 1≤n,q≤1001\le n,q\le 100; 1≤l≤r≤n1\le l\le r\le n; ∣u∣,∣v∣≤106|u|,|v|\le10^6.
  • Subtask 2 (30 points): 1≤n,q≤2000001\le n,q\le 200000; 1≤l≤r≤n1\le l\le r\le n; ∣u∣,∣v∣≤106|u|,|v|\le10^6; u=0u=0 for every update.
  • Subtask 3 (50 points): 1≤n,q≤2000001\le n,q\le 200000; 1≤l≤r≤n1\le l\le r\le n; ∣u∣,∣v∣≤106|u|,|v|\le10^6.

Example 1

Input

5 2
1 3 1 0
2 5 -1 4

Output

1 4 4 0 -1

Explanation

First array: 1,2,3,0,01,2,3,0,0. Second update adds 2,1,0,−12,1,0,-1 at indices 2 through 5.

Example 2

Input

3 2
3 3 2 -1
1 3 0 -2

Output

-2 -2 3

Explanation

Index 3 receives 5, then every index decreases by 2.