QOJ.ac

QOJ

Limite de temps : 3 s Limite de mémoire : 256 MB Points totaux : 100

#939. 大崩塌

Statistiques

Bajtek 拥有一大批高度各异的多米诺骨牌,他喜欢将它们排成一排,观察它们一个接一个倒下的样子。为了他最新的工程(他将其命名为“大倒塌”),他决定利用他所有的骨牌,并将它们按顺序放置在数轴上的某些整数坐标位置。

当 Bajtek 终于按照计划摆放好所有骨牌后,他妈妈作为生日礼物送给了他两盒新的、较小的多米诺骨牌。同一盒中的所有骨牌高度相同,且比所有已经摆放好的骨牌都要矮。此外,根据 Bajtek 的要求,其中一盒骨牌的高度是另一盒骨牌高度的倍数。由于 Bajtek 不想改变已摆放骨牌的位置,他决定将新骨牌放置在空闲的位置上。

根据“大倒塌”工程的设想,当所有骨牌都摆放好后,Bajtek 想要选择其中一个骨牌并向某个方向(左或右)推倒,使得尽可能多的骨牌倒下。根据经验,Bajtek 知道,每一块倒下的骨牌都会推倒所有距离它不超过其自身高度的后续骨牌。

Bajtek 不太确定该如何处理这些新骨牌。请你帮助他确定,如果 Bajtek 在合适的位置放置新骨牌,最多能有多少块多米诺骨牌倒下。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 200\,000$),表示 Bajtek 最初拥有的骨牌数量,以及他在“大倒塌”工程中摆放的骨牌数量。

接下来的 $n$ 行描述了 Bajtek 骨牌的摆放位置:第 $i$ 行包含两个整数 $x_i, h_i$ ($0 \le x_i \le 10^{18}$, $x_{i-1} < x_i$, $1 \le h_i \le 2\,000\,000$),分别表示第 $i$ 块骨牌的位置和高度,中间用空格隔开。

最后一行包含四个整数 $N_1, H_1, N_2, H_2$ ($0 \le N_1, N_2 \le 10^{18}$, $1 \le H_1, H_2 \le 10^6$),分别表示第一盒骨牌的数量和高度,以及第二盒骨牌的数量和高度,中间用空格隔开。新骨牌比旧骨牌矮,因此对于所有的 $i$,都有 $H_1, H_2 < h_i$。根据 Bajtek 的要求,高度满足整除关系,即 $H_2$ 整除 $H_1$ 或 $H_1$ 整除 $H_2$。

输出格式

输出一个整数,表示在“大倒塌”工程中最多能倒下的多米诺骨牌数量。

样例

输入 1

3
1 5
10 6
20 7
1 4 2 1

输出 1

5

说明 1

一种可能的情况是:将高度为 $4$ 的骨牌放置在位置 $6$,将高度为 $1$ 的骨牌放置在位置 $4$ 和 $5$,然后向右推倒位置 $1$ 处的骨牌。

子任务

子任务 条件 分值
1 $n \le 2000$ 25
2 $H_1 = H_2$ 25
3 无附加条件 50

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.