Codeforces Round 1067 (Div. 2)
E
Sink
Codeforces
2600
原题
← DF1 →
翻译中…

You are given a grid containing $n$ rows and $m$ columns. Every cell $(i, j)$, located in the $i$-th row and $j$-th column, has a positive integer value associated with it $a_{i, j}$. Two cells are adjacent if and only if they share a common side in the grid.

翻译中…

You are allowed to construct holes at cells of your choice. A cell $(x, y)$ is a sink if and only if it has a hole, or is adjacent to a sink $(i, j)$ with $a_{x, y} \ge a_{i, j}$.

翻译中…

The beauty of a grid is defined as the minimum number of holes you need to construct so that every cell becomes a sink.

翻译中…

You have to determine the beauty of this grid.

翻译中…

You are also given $q$ queries.

翻译中…

In a query, you are given three positive integers $r$, $c$, and $x$. The current value of cell $(r, c)$ is decreased by $x$. After each query, determine the beauty of the grid considering no holes have been constructed yet.

翻译中…

Note that queries are cumulative, so the effects of each query carry on to future queries.

翻译中…

It is guaranteed that after every query the value of each cell will remain positive.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$, $1 \le n \cdot m \le 2 \cdot 10^5$) — the number of rows and columns, respectively.

翻译中…

The following $n$ lines contain $m$ integers each; the $j$-th element in the $i$-th line $a_{i, j}$ is the number written in the $j$-th cell of the $i$-th row ($1 \le a_{i,j} \le 10^9$).

翻译中…

The next line contains a single integer $q$ ($0 \le q \le 2\cdot 10^5$) — the number of queries.

翻译中…

The following $q$ lines contain $3$ integers each — $r, c,$ and $x$ ($1\le r \le n, 1\le c \le m, 1\le x \lt 10^9$).

翻译中…

It is guaranteed that the sum of $n \cdot m$ and the sum of $q$ over all test cases does not exceed $2 \cdot 10^5$.

翻译中…

It is guaranteed that after every query the value of each cell will remain positive.

翻译中…

Output

翻译中…

For each test case, print $q+1$ lines.

翻译中…

On the first line print the beauty of the initial grid.

翻译中…

Also, after each query, print the beauty of the current grid.

翻译中…

Note

翻译中…

For the first test case:

翻译中…
  • Initially, we can create a hole at cell ($1,1$).
  • After the first query, we can create a hole at cell ($1,1$).
  • After the second query, we can create holes at cells ($1,1$) and ($1,3$).
翻译中…

For the second test case:

翻译中…
  • Initially, we can create holes at cells ($1,2$), ($2,1$), ($2,3$), and ($3,2$).
  • After the first query, we can create holes at cells ($1,2$), ($2,1$), ($2,3$), and ($3,2$).
  • After the second query, we can create a hole at cell ($2,2$).
  • After the third query, we can create holes at cells ($2,2$) and ($3,3$).
翻译中…

样例

Input #1
3
1 4
1 2 3 5
2
1 4 1
1 3 2
3 3
5 1 6
2 9 3
7 4 8
3
2 2 1
2 2 7
3 3 7
3 4
10 10 10 10
10 10 10 10
10 10 11 10
5
3 3 5
2 2 5
2 4 5
2 3 5
1 1 9
Output #1
1
1
2
4
4
1
2
1
1
2
3
1
2
InputCopy OutputCopy
题目信息
题号
2158E
时间限制
3 s
内存限制
256 MB
标签
数据结构
分治
并查集
图论
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。