QOJ.ac

QOJ

时间限制: 1 s 内存限制: 512 MB 总分: 100

#168. 立方体分割

统计

Pablo Cubarson 是一位著名的立体主义艺术家。他正在用一个由 $A \times B \times C$ 个单位立方体组成的长方体创作一件新作品。他计划通过移除 $N$ 个单位立方体来塑造一个美丽的形状。当他准备开始工作时,他注意到移除这些立方体可能会导致长方体分裂成几个互不相连的部分。这违背了他的审美,因此他想知道他的计划会产生多少个部分。

你的任务是计算移除 $N$ 个立方体后,长方体中剩余部分的连通分量数量。如果两个立方体共享一个面,则它们是连通的。

输入格式

第一行包含四个整数 $A, B, C$ 和 $N$。$A, B, C$ ($1 \le A, B, C \le 10^6$) 表示长方体的尺寸——长方体从左到右的宽度为 $A$ 个单位,从底到顶的高度为 $B$ 个单位,从前到后的深度为 $C$ 个单位。$N$ ($0 \le N \le 2 \cdot 10^4, N \le A \times B \times C - 1$) 表示 Cubarson 计划中移除的立方体数量。接下来的 $N$ 行,每行包含三个整数 $X_i$ ($0 \le X_i \le A - 1$),$Y_i$ ($0 \le Y_i \le B - 1$) 和 $Z_i$ ($0 \le Z_i \le C - 1$)。它们表示位于从左侧起第 $X_i$ 个位置、从底部起第 $Y_i$ 个位置、从前方起第 $Z_i$ 个位置的立方体将被移除。你可以假设给定的位置各不相同。

输出格式

输出移除指定立方体后,长方体中剩余部分的连通分量数量。

样例

样例输入 1

2 2 2 4
0 0 0
1 1 0
1 0 1
0 1 1

样例输出 1

4

样例输入 2

3 3 3 1
1 1 1

样例输出 2

1

样例输入 3

1 1 3 2
0 0 0
0 0 2

样例输出 3

1

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.