Under construction

Still being built. Things may change

Quarry

Interview

Time limit1sMemory limit1024 MB

Summary
Apply K range commands that each lower the elevations on [S, E] by H to an initial array, then print every final elevation.
Level

Easy3 of 10

Topics
Prefix sum, Array
Solved
No attempts yet

Statement

Useful minerals were found on a plot of land. The owner plans to install a new automatic excavation system, operate it, and turn the plot into a quarry.

The system digs one pit at a time. A pit starts at position SiS_i and ends at position EiE_i, both measured in meters from the start of the quarry, and its depth is HiH_i meters.

The quarry can be drawn as a two-dimensional diagram that shows the elevation above sea level along the quarry, both at the beginning and after mineral extraction starts.

The system works by carrying out excavation commands. Each command lowers the elevation by HiH_i meters on the interval [Si,Ei][S_i, E_i]. Figure 1 shows the elevation after two commands: the first digs on [0;2][0; 2], the second digs on [1;3][1; 3], and each digs a pit 1 meter deep. The area dug by the first command is green (light gray in the grayscale print), and the area dug by the second is blue (gray in the grayscale print).

Figure 1.

The owner knows which excavation commands will be given to the system. Before starting, the owner wants to know what the quarry will look like after all commands are executed.

Find the elevation of the quarry after all excavation commands are executed.

Input

The first line contains two integers, the length of the quarry NN and the number of commands KK.

The second line contains NN integers AiA_i, the initial elevation above sea level at ii meters from the start of the quarry. The first value is the elevation at 0 meters from the start.

Each of the next KK lines contains three integers SiS_i, EiE_i, and HiH_i, the start, end, and depth of the ii-th excavation command.

Output

Print NN numbers. The ii-th number is the elevation at ii meters from the start of the quarry after all commands are executed.

The final elevation can be negative.

Constraints

0≤Si≤Ei<N≤250 0000 \le S_i \le E_i < N \le 250\,000

1≤K≤250 0001 \le K \le 250\,000

−1 000≤Ai,Hi≤1 000-1\,000 \le A_i, H_i \le 1\,000

Examples2

  1. Example 1

    Input
    5 2
    3 4 3 2 1
    0 2 1
    1 3 1
    
    Expected output
    2 2 1 1 1
    
  2. Example 2

    Input
    4 2
    4 -2 4 0
    0 3 3
    0 2 1
    
    Expected output
    0 -6 0 -3