Universal Cup Judging System

Universal Cup

Süre Sınırı: 2.0 s Bellek Sınırı: 1024 MB Toplam puan: 100 Zorluk: [göster] Hack'lenebilir ✓
İstatistikler

小青魚有一個 $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-連通)。

problem_18013_1.png

例如,考慮上述情況(黑色單元格表示已刪除的單元格,白色單元格表示未刪除的單元格),單元格 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

以下是每個單元格被染成黑色的順序。

problem_18013_2.png

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.