QOJ.ac

QOJ

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

#7038. 地毯移除

統計

Mike 的客厅铺有 $m^2$ 块方砖。这些方砖构成了一个 $m \times m$ 的网格,其中行从上到下编号为 $1$ 到 $m$,列从左到右编号为 $1$ 到 $m$。

地板上铺有 $n$ 块矩形地毯,其边与网格的边平行。每块地毯覆盖了若干连续行和若干连续列的交集,形成一个矩形。具体来说,第 $i$ 块地毯由四个整数 $x_l, x_r, y_l, y_r$ 描述,其中 $1 \le x_l \le x_r \le m$ 且 $1 \le y_l \le y_r \le m$,表示该地毯覆盖了所有行号在 $x_l$ 到 $x_r$ 之间且列号在 $y_l$ 到 $y_r$ 之间的方砖。

现在 Mike 请你移走恰好两块地毯,以使至少被一块剩余地毯覆盖的方砖数量最少。

上图描述了样例情况,其中两个带有虚线边界的矩形区域表示移除两块地毯的一种最优方案。

输入格式

输入包含多个测试用例。第一行包含一个正整数 $T$,表示测试用例的数量,最多为 $1000$。

对于每个测试用例,第一行包含两个整数 $n$ 和 $m$,分别表示地毯的数量和每行或每列的方砖数量,其中 $3 \le n \le 3 \times 10^5$ 且 $1 \le m \le 1500$。

接下来的 $n$ 行,每行包含四个整数 $x_l, x_r, y_l, y_r$,描述铺在地板上的一块地毯及其位置,其中 $1 \le x_l \le x_r \le m$ 且 $1 \le y_l \le y_r \le m$。

保证所有测试用例中 $n$ 的总和不超过 $2 \times 10^6$,所有测试用例中 $m^2$ 的总和不超过 $5 \times 10^7$。

输出格式

对于每个测试用例,输出一行,包含移除两块地毯后,至少被一块剩余地毯覆盖的方砖的最小数量。

样例

输入 1

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

输出 1

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.