#P9286. Matrix Maximum Query
Matrix Maximum Query
Matrix Maximum Query
Given an \(n \times m\) matrix \(a\) with all distinct numbers, you need to process \(q\) updates. In each update, a number in the matrix is increased to a new, larger value. It is guaranteed that after each update all numbers remain distinct.
After each update, determine and output the number of elements in the matrix that are both the maximum in their row and the maximum in their column.
inputFormat
The first line contains two integers \(n\) and \(m\). The next \(n\) lines each contain \(m\) integers representing the matrix \(a\).
The following line contains an integer \(q\), the number of updates. Each of the next \(q\) lines contains three integers \(i\), \(j\), and \(x\), indicating that \(a_{i,j}\) (1-indexed) is updated to \(x\). It is guaranteed that \(x\) is greater than the previous value at \(a_{i,j}\).
outputFormat
For each update, output a single line containing one integer – the count of numbers in the updated matrix that are the maximum in both their respective row and column.
sample
2 2
1 2
3 4
1
1 1 5
2
</p>