#P4231. Pillars Damage Calculation

    ID: 17478 Type: Default 1000ms 256MiB

Pillars Damage Calculation

Pillars Damage Calculation

There are \(N\) pillars arranged in a line, initially with a damage value of 0. Then \(M\) attacks occur. Each attack is described by four integers \(l, r, s, e\). The attack affects pillars from the \(l\)-th to the \(r\)-th (inclusive) by applying an arithmetic progression of damage such that the first affected pillar receives \(s\) damage and the last receives \(e\) damage. For example, if \(l=1, r=5, s=2, e=10\), then the pillars 1 to 5 will receive damages \(2, 4, 6, 8, 10\) respectively. The task is to compute the final damage on each pillar after all attacks have been executed.

inputFormat

The first line contains two integers \(N\) and \(M\) separated by a space, where \(N\) is the number of pillars and \(M\) is the number of attacks. Each of the next \(M\) lines contains four integers \(l, r, s, e\), representing an attack on pillars from index \(l\) to \(r\) (inclusive) that applies damage following an arithmetic progression starting at \(s\) and ending at \(e\).

outputFormat

Output a single line containing \(N\) integers separated by spaces. The \(i\)-th integer represents the total damage on the \(i\)-th pillar after all attacks.

sample

5 1
1 5 2 10
2 4 6 8 10