QOJ.ac

QOJ

実行時間制限: 10 s メモリ制限: 512 MB 満点: 100 ハック可能 ✓

#11519. 监禁

統計

Bobo 有一个大小为 $n \times m$ 的矩阵,其中填满了整数。保证所有包含相同值的单元格都是 4-连通的。

定义值为 $x$ 的连通分量的“囚禁” $J_x$ 为覆盖该分量所有单元格的最小面积矩形(边与矩阵边平行)。

对于每个囚禁 $B_x$,Jessica 想要计算以下值:

$$s(B_x) = \sum_{B_y \in A \setminus \{x\}} f(B_x, B_y) \cdot y$$

其中 $A$ 是矩阵中所有整数的集合,且

$$f(B_x, B_y) = \begin{cases} 0 & B_x \text{ 和 } B_y \text{ 的交集面积为 } 0 \\ 0 & B_x \text{ 完全在 } B_y \text{ 内部,或反之亦然} \\ 1 & \text{其他情况} \end{cases}$$

输入格式

输入包含多个测试用例,以文件结束符(EOF)终止。对于每个测试用例:

第一行包含两个整数 $n$ 和 $m$,表示矩阵的大小。

第二行包含 $n \cdot m$ 个整数 $a_{1,1}, a_{1,2}, \dots, a_{1,m}, a_{2,1}, a_{2,2}, \dots, a_{2,m}, \dots, a_{n,1}, a_{n,2}, \dots, a_{n,m}$,其中 $a_{i,j}$ 是第 $i$ 行第 $j$ 列的值。

  • $1 \le n \cdot m \le 10^6$
  • $1 \le a_{i,j} \le nm$
  • 保证所有包含相同值的单元格都是 4-连通的。
  • 保证所有测试用例中 $n \cdot m$ 的总和不超过 $10^7$。

输出格式

对于每个测试用例,输出一个整数,表示 $\bigoplus_{x \in A} s(x) \oplus x$ 的值,其中 $\oplus$ 表示异或(XOR)运算符。

样例

输入 1

4 2
4 8 4 4 4 2 2 2
2 7
12 12 12 13 8 9 14 12 12 7 4 10 11 5
3 5
13 13 3 3 14 2 2 1 1 11 2 2 1 5 7

输出 1

20
93
56

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.