QOJ.ac

QOJ

Time Limit: 4 s Memory Limit: 512 MB Total points: 100

#4417. 浅月

Statistics

在一个 $m \times m$ 的网格中,左上角单元格为 $(1, 1)$,右下角单元格为 $(m, m)$。最初,所有单元格均为白色。小 Q 在网格上绘制了 $n$ 个黑色的 $w \times h$ 矩形。对于第 $i$ 个矩形,小 Q 选择一个单元格 $(a_i, b_i)$,并将所有满足 $a_i \le x \le a_i + w - 1$ 且 $b_i \le y \le b_i + h - 1$ 的单元格 $(x, y)$ 涂成黑色。

在小 Q 完成所有工作后,他想知道有多少对白色单元格是 4-连通的。请编写一个程序来计算:

$$\sum_{(i,j) \mid 1 \le i, j \le m, (i, j) \text{ is white}} f(i, j)$$

其中 $f(i, j)$ 是与 $(i, j)$ 4-连通的白色单元格的数量(包含 $(i, j)$ 本身)。

如果两个单元格共享一条公共边,则称它们是相邻的。如果存在一个白色单元格序列 $c_1, c_2, \dots, c_k$ 满足以下条件,则称两个白色单元格 $(i, j)$ 和 $(x, y)$ 是 4-连通的:

  • $c_1 = (i, j)$。
  • $c_k = (x, y)$。
  • 对于所有 $1 \le i < k$,$c_i$ 和 $c_{i+1}$ 相邻。

输入格式

第一行包含一个整数 $T$ ($1 \le T \le 1000$),表示测试用例的数量。每个测试用例:

第一行包含四个整数 $n, m, w$ 和 $h$ ($1 \le n \le 100\,000, 1 \le w, h \le m \le 10^9$),分别表示矩形的数量、网格的大小以及每个矩形的大小。

接下来的 $n$ 行,每行包含两个整数 $a_i$ 和 $b_i$ ($1 \le a_i \le m - w + 1, 1 \le b_i \le m - h + 1$),表示一个矩形。

保证所有 $n$ 的总和不超过 $2\,000\,000$。

输出格式

对于每个测试用例,输出一行包含一个整数,表示答案。注意答案可能非常大,请输出其对 $2^{64}$ 取模的结果。

样例

输入 1

1
4 6 2 2
1 3
2 2
3 5
4 1

输出 1

201

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.