#P9286. [ROI 2018] Extraction of radium

[ROI 2018] Extraction of radium

Background

Translated from ROI 2018 Day1 T1. Добыча радия (Extraction of radium).

Problem Description

You are given an n×mn \times m matrix aa, and all numbers in the matrix are pairwise distinct.
Then there are qq updates. Each update changes one value to a larger value. It is guaranteed that after each update, all numbers in the matrix are still pairwise distinct.

After each update, compute how many numbers in the matrix are both the maximum in their row and the maximum in their column.

Input Format

The first line contains three integers nn, mm, qq, representing the size of the matrix and the number of updates.
The next nn lines each contain mm integers, describing the matrix.
The next qq lines each contain three integers xx, yy, tt, meaning to change the element in row xx and column yy to tt.

Output Format

Output qq lines, each containing one integer, representing after each update how many numbers in the matrix satisfy the condition.

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

Hint

Constraints: For all testdata, 1a(i,j)1071 \leq a(i,j) \leq 10^7, 1t1071 \leq t \leq 10^7, 1n,m,q2×1051 \leq n, m, q \leq 2 \times 10^5.

Subtask ID n,mn,m qq
11 1n×m1001 \leq n \times m \leq 100 1q1001 \leq q \leq 100
22 1n×m50001 \leq n \times m \leq 5000 1q50001 \leq q \leq 5000
33 1n,m4001 \leq n,m \leq 400 1q2×1051 \leq q \leq 2 \times 10^5
44 1n×m2×1051 \leq n \times m \leq 2 \times 10^5

Translated by ChatGPT 5