#P11882. Candy Bag Absolute Mode
Candy Bag Absolute Mode
Candy Bag Absolute Mode
You are given an n x n grid of candy bags. The bag in the ith row and jth column is denoted as (i,j)
.
There are q operations. Each operation is described by a 6-tuple: \( (x_1, y_1, x_2, y_2, c, k) \). This means that for every bag \( (i,j) \) where \( x_1 \le i \le x_2 \) and \( y_1 \le j \le y_2 \), you add \( k \) candies of color \( c \).
After all operations, for each bag, you need to determine its absolute mode color. A candy color is defined as the absolute mode for a bag if and only if its count is strictly greater than the sum of counts of all other colors in that bag. If no such color exists, output -1
for that bag.
inputFormat
The first line contains two integers \( n \) and \( q \) (the grid dimension and the number of operations).
Each of the next \( q \) lines contains six integers: \( x_1\ y_1\ x_2\ y_2\ c\ k \), representing an operation.
outputFormat
Output the grid of results in \( n \) lines. Each line contains \( n \) integers separated by a single space. The \( jth\) number in the \( ith\) line should be the absolute mode candy color in bag \( (i,j) \), or -1
if it does not exist.
sample
2 1
1 1 2 2 3 5
3 3
3 3
</p>