#C10561. Maximum Consecutive Bears
Maximum Consecutive Bears
Maximum Consecutive Bears
Mike is organizing a game for his bear friends. The bears are arranged in an \(n \times m\) grid. Initially, no bear holds any flag.
During the game, Mike performs a series of \(q\) updates. In each update, a bear at position \((i, j)\) is assigned a flag color: red (represented by 0) or blue (represented by 1). If the bear already has a flag, its color is changed to the new one.
After each update, Mike wants to determine the maximum number of consecutive bears holding the same colored flag in the updated row or column. Note that only cells with assigned flags (i.e. not in the initial state) are counted in a consecutive sequence.
For example, if the first update sets cell (1, 1) to red, then the answer after that update is 1. If a subsequent update causes the first row to have two red flags consecutively, then the answer for that update will be 2.
Note: The consecutive count is computed only for the row and the column that are updated, and the answer for each update is the maximum of the two counts.
inputFormat
The first line contains three integers \(n\), \(m\), and \(q\) representing the number of rows, columns, and updates, respectively.
Each of the following \(q\) lines contains three integers \(i\), \(j\), and \(c\) where \(i\) and \(j\) denote the 1-indexed row and column of the bear to update, and \(c\) is the flag color (0 for red, 1 for blue).
outputFormat
Output a single line with \(q\) integers separated by spaces. The \(k\)-th integer represents the maximum number of consecutive bears holding the same colored flag in the updated row or column after the \(k\)-th update.
## sample2 2 1
1 1 0
1
</p>