QOJ.ac

QOJ

حد الوقت: 1.0 s حد الذاكرة: 1024 MB مجموع النقاط: 100

#7550. 高效害虫管理

الإحصائيات

有一块田地毗邻一条笔直的道路。假设道路位于 $Ox$ 轴上。田地的每一条边界边要么是水平的,要么是垂直的。最左侧和最右侧的边是垂直的,并与位于道路上的基边相邻。基边的长度等于所有其他水平边长度之和。如下图所示:

边界上或田地内部的点代表受虫害侵扰的位置。为了有效地根除虫害,农场主试图将受侵扰的区域划分为若干个满足以下条件的矩形区域:

  • 每个矩形区域必须包含在田地内。矩形的边允许与田地的边界重合。
  • 矩形区域的每一条边要么是水平的,要么是垂直的。
  • 矩形区域之间完全分离,包括它们的边界。
  • 每个虫害侵扰位置必须包含在其中一个矩形区域内。虫害侵扰位置允许位于矩形的边上。

下图展示了覆盖所有虫害侵扰位置的四个矩形区域。农场主希望最小化矩形区域的数量,以实现高效的虫害管理。

给定田地的边界和虫害侵扰位置,编写一个程序来计算满足上述条件的最小矩形区域数量。

输入格式

输入的第一行包含两个整数 $m$ ($4 \le m \le 100\,000$) 和 $n$ ($0 \le n \le 100\,000$),其中 $m$ 是田地边界边的数量,$n$ 是虫害侵扰位置的数量。

第二行包含 $m$ 个整数 $v_1, v_2, \dots, v_m$ ($v_1 = v_m = 0, 0 \le v_i \le 10^6$)。这些整数交替表示垂直边的 $x$ 坐标和水平边的 $y$ 坐标。当从基边的左端沿顺时针方向遍历田地的上边界到右端时,会交替遇到这些垂直边和水平边。因此,遍历中的第一条边是从 $(v_1, 0)$ 到 $(v_1, v_2)$ 的垂直边,下一条边是从 $(v_1, v_2)$ 到 $(v_3, v_2)$ 的水平边,依此类推。

从第三行开始,接下来的 $n$ 行,每行包含两个整数 $x$ 和 $y$,表示一个虫害侵扰位置的坐标。所有位置都在田地的边界上或内部。

保证基边的长度等于所有其他水平边长度之和。

输出格式

输出仅一行,包含一个整数,表示满足上述条件的最小矩形区域数量。

样例

样例输入 1

12 8
0 30 20 20 30 40 40 10 50 20 70 0
4 5
15 26
25 15
35 15
35 35
50 5
55 15
60 20

样例输出 1

4

样例输入 2

4 0
0 10 50 0

样例输出 2

0

样例输入 3

12 3
0 3 2 6 4 1 6 4 8 2 10 0
3 5
7 3
3 1

样例输出 3

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.