QOJ.ac

QOJ

実行時間制限: 2.0 s メモリ制限: 1024 MB 満点: 100 難易度: [表示] ハック可能 ✓

#18013. Rectangle Flip 3

統計

小青鱼有一个 $n$ 行 $m$ 列的矩形,行和列的索引均从 $0$ 开始。第 $i$ 行第 $j$ 列的单元格可以表示为 $(i, j)$($0 \le i \le n - 1, 0 \le j \le m - 1$)。最初,所有单元格都存在(未被删除)。

小青鱼称两个单元格 $(x_a, y_a)$ 和 $(x_b, y_b)$ 是相邻的,当且仅当 $|x_a - x_b| + |y_a - y_b| = 1$。换句话说,这两个单元格共享一条公共边界(也称为 4-相邻)。对于两个单元格 $p = (x_a, y_a)$ 和 $q = (x_b, y_b)$,如果它们可以通过一系列相邻且未被删除的单元格连接在一起,则称单元格 $p$ 和 $q$ 是连通的(4-连通)。

例如,考虑上述情况(黑色单元格表示已删除的单元格,白色单元格表示未删除的单元格),单元格 A 和单元格 B 是相邻的。单元格 A 与单元格 B 和单元格 C 连通,但单元格 A 和单元格 D 不连通。

现在,小青鱼要在梦中进行一些操作。在每次操作中,小青鱼会选择一个单元格 $(x, y)$ 并删除单元格 $(x, y)$。

小青鱼非常好奇,在每次删除之后,当前矩形中剩余的未删除单元格中,有多少个是割点。具体来说:

  • 对于某个单元格 $r = (x_r, y_r)$,如果存在两个单元格 $p = (x_p, y_p)$ 和 $q = (x_q, y_q)$,使得 $p$ 和 $q$ 在网格中是连通的,但在删除单元格 $r$ 后不再连通,则称 $r$ 为一个割点

例如,在上图中,单元格 E 是一个割点。因为对于单元格 A 和单元格 C,它们在删除单元格 E 之前是连通的,但在删除单元格 E 之后不再连通。

然而,由于小青鱼的梦境非常神奇,你无法预测他后续的操作。因此,你需要在线回答所有这些操作。具体来说,第 $i$ 次($2 \le i \le q$)操作中给定的 $(x, y)$ 将取决于第 $i-1$ 次操作返回的结果。请在此限制下帮助小青鱼回答所有查询。

输入格式

第一行包含三个整数 $n$,$m$ 和 $q$($2 \le n, m \le 500$,$1 \le q \le n \cdot m$)。

接下来的 $q$ 行,每行包含两个整数 $x'_i, y'_i$($0 \le x'_i < n, 0 \le y'_i < m$),表示加密后的被删除单元格的坐标 $(x_i, y_i)$。如果上一次查询的答案为 $preans$,则真实的 $x_i = (x'_i + preans) \bmod n$,$y_i = (y'_i + preans) \bmod m$。初始时,我们认为 $preans = 0$。

保证解密后的 $(x_i, y_i)$ 两两不同。也就是说,同一个单元格不会被多次删除。

输出格式

对于每次操作,输出一行包含一个整数,表示该删除操作后割点的数量。

样例

输入样例 1

5 5 12
0 1
0 1
1 4
2 3
4 1
2 4
1 1
4 2
2 1
4 2
1 0
0 0

输出样例 1

1
2
2
6
5
7
10
7
6
7
7
4

说明

解密后的数据:

5 5 12
0 1
1 2
3 1
4 0
0 2
2 4
3 3
4 2
4 3
0 3
3 2
2 2

以下是每个单元格被染成黑色的顺序。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.