Skittlez

Time limit: 2s Memory limit: 256MB Input: Output:

Skittlez. Taste the rainbow, solve the rainbow.

Mr. Rainbow McRainbows is the employee of the month in the Skittlez factory's Department of Rainbow Packing (as he is the only one working in this department).

For those unfamiliar with them, a bag of Skittlez is filled with small, round, colorful pieces of candy that taste like fruits. If you ever wondered how they are packed and why there are never enough green ones in a bag, today is your lucky day, as Mr.~McRainbows will give you an exclusive into how the Skittlez bags are filled.

Task

The Rainbow Packing Department has two components: the bags grid and the filling machine. The bags grid is divided into NN rows (numbered from 11 to NN) and NN columns (numbered from 11 to NN), where each cell contains a bag that has to be filled with candy of various colors. The filling machine is used to pour candy into the bags from the grid and takes commands of the following type: (x1,y1,x2,y2,c,k)(x_1, y_1, x_2, y_2, c, k), meaning that in each bag from a cell (i,j)(i, j) with x1ix2x_1 \leq i \leq x_2 and y1jy2y_1 \leq j \leq y_2, the machine will pour kk candy pieces of color cc.

Mr. McRainbows has a fairly boring job, with his only responsibility being to operate the filling machine. At the beginning of each day, all the bags in the grid are empty, and Rainbow's supervisors give him a list of commands that he has to enter into the machine. Hence, he decided to write a program that does his job for him so he can focus on more intellectual activities like playing Solitaire.

Unfortunately, his supervisors started getting suspicious when they saw how much his high score increased (as with any respectable company, Skittlez has an internal Solitaire scoreboard). Consequently, they asked him to file a report at the end of each day stating which of the packed bags contain an overwhelming color. A color is considered overwhelming for a bag if there are strictly more candy pieces of that color in the bag than all others in the bag combined.

Because he doesn't really know how to do that, and he doesn't want to waste a few days figuring it out, he asks you to write a program that will compute the report. Formally, you are given the size of the bags grid NN and the list of commands the machine receives in a day, and you want to output a matrix BB with the same number of rows and columns as the grid where:

Bi,j={c,if the overwhelming color in the bag in cell (i,j) is c,1,otherwise.B_{i, j} = \begin{cases} c, & \text{if the overwhelming color in the bag in cell $(i, j)$ is $c$,} \\ -1, & \text{otherwise.} \end{cases}

Input data

The first line of the input contains two positive integer numbers NN, the size of the bags grid, and QQ, the number of commands the machine receives on the given day.

Each of the next QQ lines contains six positive integers, x1x_1, y1y_1, x2x_2, y2y_2, cc and kk, describing a command. The values on each input line are separated by spaces.

Output data

Output NN lines, each containing NN space-separated integers, representing the matrix BB described above.

Restrictions and clarifications

  • 1N1 0001 \leq N \leq 1 \ 000
  • 1Q500 0001 \leq Q \leq 500 \ 000
  • 1x1x2N1 \leq x_1 \leq x_2 \leq N
  • 1y1y2N1 \leq y_1 \leq y_2 \leq N
  • 1cQ1 \leq c \leq Q
  • 1k1091 \leq k \leq 10^9
  • Note! The extra spaces in the examples' output have been added for better visibility; you should print only one space between any two consecutive values.
# Points Restrictions
1 7 N,Q20N, Q \leq 20 and k5k \leq 5
2 21 There are at most 2020 different candy colours.
3 44 N300N \leq 300 and Q100 000Q \leq 100 \ 000
4 28 No further restrictions.

Example 1

stdin

5 3
1 3 5 5 3 3
2 2 4 4 1 5
1 1 3 5 1 3

stdout

 1  1 -1 -1 -1
 1  1  1  1 -1
 1  1  1  1 -1
-1  1  1  1  3
-1 -1  3  3  3

Example 2

stdin

10 10
1 6 6 10 2 4
5 4 9 8 2 5
2 7 6 9 2 3
6 3 10 9 6 4
1 2 2 10 1 3
5 1 7 6 1 3
9 1 9 2 2 4
4 6 8 7 2 3
2 5 3 7 2 4
1 8 6 10 2 3

stdout

-1  1  1  1  1  2  2  2  2  2
-1  1  1  1  2  2  2  2  2  2
-1 -1 -1 -1  2  2  2  2  2  2
-1 -1 -1 -1 -1  2  2  2  2  2
 1  1  1  2  2  2  2  2  2  2
 1  1  6 -1 -1  2  2  2  2  2
 1  1  6 -1 -1  2  2  2  6 -1
-1 -1  6  2  2  2  2  2  6 -1
 2  2  6  2  2  2  2  2  6 -1
-1 -1  6  6  6  6  6  6  6 -1

Log in or sign up to be able to send submissions!