QOJ.ac

QOJ

时间限制: 1 s 内存限制: 128 MB 总分: 10

#11650. 农夫的田地

统计

Byteland 的国土呈矩形,宽为 $a$ 米,高为 $b$ 米。Byteasar 是一位农民,他拥有一块由单位正方形组成的田地。此外,Byteasar 田地的每一水平层与该田地的交集都是连通的(尽管整个田地可能是不连通的)。

Byteland 国王颁布了一项法令,要求每位农民上交一块宽为 $c$ 米、高为 $d$ 米的矩形区域(可水平或垂直放置),该区域由单位正方形组成。这个矩形的位置将由国王选定。Byteasar 希望这种矩形有许多可能的放置位置,这样贪婪的国王就无法迅速做出决定。请帮助 Byteasar 计算出他可能失去的区域(即位于 Byteasar 田地内部的区域)的可能位置数量。

编写一个程序:

  • 读取 Byteasar 田地的描述以及必须上交给国王的矩形区域的尺寸;
  • 计算该区域在 Byteasar 田地中可能的放置位置数量;
  • 将答案输出到标准输出。

输入格式

标准输入的第一行包含四个整数 $a$、$b$、$c$ 和 $d$($1 \le a, b, c, d \le 5\,000\,000$)。这些数字分别表示:Byteland 的尺寸以及必须上交给国王的区域的尺寸。接下来的 $b$ 行描述了农民田地的连续水平层。每行描述包含两个整数 $x$ 和 $l$($1 \le x \le a$,$0 \le l \le a$,$x + l \le a + 1$),表示该层田地的片段从距离 Byteland 左边界 $x - 1$ 米处开始,包含 $l$ 个单位正方形。

输出格式

输出一个整数到标准输出。该整数应为宽 $c$ 米、高 $d$ 米的矩形区域在 Byteasar 田地内部可能的放置位置数量。

样例

输入 1

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

输出 1

3

该图描绘了样例输入中的田地(深色部分代表属于田地的区域)。

我们建议 C++ 程序员谨慎使用 STL 数据结构,因为数据规模较大。使用不当可能会导致超出时间或内存限制。

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.