#C7883. Apply Operations on a Grid

    ID: 51803 Type: Default 1000ms 256MiB

Apply Operations on a Grid

Apply Operations on a Grid

You are given an \( n \times n \) grid that is initially filled with zeros. You need to perform \( q \) operations. Each operation is represented by five integers \( r_1, c_1, r_2, c_2, x \), which means that you need to add \( x \) to every cell in the subgrid defined by its top-left corner \( (r_1, c_1) \) and bottom-right corner \( (r_2, c_2) \). After processing all operations, output the final state of the grid.

The update performed for each cell in the specified subgrid can be written in LaTeX as follows:

$$grid[i][j] \mathrel{+}= x$$

Note that the indices in the input are 1-indexed while most programming languages use 0-indexed arrays. You will need to adjust the indices accordingly.

inputFormat

The first line contains two integers \( n \) and \( q \) separated by a space, where \( n \) is the size of the grid and \( q \) is the number of operations.

The next \( q \) lines each contain five integers \( r_1, c_1, r_2, c_2, x \), representing an operation where \( (r_1, c_1) \) is the top-left corner and \( (r_2, c_2) \) is the bottom-right corner of the subgrid, and \( x \) is the value to be added to each cell in that subgrid.

Note: Indices are 1-indexed.

outputFormat

Print the final grid after all operations. Each of the \( n \) lines should contain \( n \) space-separated integers representing a row of the grid.

## sample
3 1
1 1 2 2 5
5 5 0

5 5 0 0 0 0

</p>