CF989D.A Shade of Moonlight
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Gathering darkness shrouds the woods and the world. The moon sheds its light on the boat and the river.
"To curtain off the moonlight should be hardly possible; the shades present its mellow beauty and restful nature." Intonates Mino.
"See? The clouds are coming." Kanno gazes into the distance.
"That can't be better," Mino turns to Kanno.
The sky can be seen as a one-dimensional axis. The moon is at the origin whose coordinate is 0.
There are n clouds floating in the sky. Each cloud has the same length l. The i-th initially covers the range of (xi,xi+l) (endpoints excluded). Initially, it moves at a velocity of vi, which equals either 1 or −1.
Furthermore, no pair of clouds intersect initially, that is, for all 1≤i<j≤n, ∣xi−xj∣≥l.
With a wind velocity of w, the velocity of the i-th cloud becomes vi+w. That is, its coordinate increases by vi+w during each unit of time. Note that the wind can be strong and clouds can change their direction.
You are to help Mino count the number of pairs (i,j) (i<j), such that with a proper choice of wind velocity w not exceeding wmax in absolute value (possibly negative and/or fractional), the i-th and j-th clouds both cover the moon at the same future moment. This w doesn't need to be the same across different pairs.
聚集的黑暗笼罩着森林与世界。月光洒落在小船与河流之上。
“想要遮蔽月光,恐怕难以做到;云影却映衬出它柔和的美与宁静的本质。”美浓吟诵道。
“看,云朵正飘来。”观乃眺望远方。
“再好不过了。”美浓转向观乃。
天空可被视作一条一维数轴,月亮位于原点,其坐标为 0。
天空中漂浮着 n 朵云。每朵云长度均为 l。第 i 朵云初始时刻覆盖区间 (xi,xi+l)(端点不包含在内)。初始时,它以速度 vi 移动,其中 vi 取值为 1 或 −1。
此外,任意两朵云在初始时刻互不相交,即对所有满足 1≤i<j≤n 的 i,j,均有 ∣xi−xj∣≥l。
当风速为 w 时,第 i 朵云的速度变为 vi+w。换言之,其坐标在单位时间内增加 vi+w。注意:风可能很强劲,云朵甚至可能改变运动方向。
你需要帮助美浓计算满足如下条件的数对 (i,j)(其中 i<j)的个数:存在某个风速 w(其绝对值不超过 wmax,可为负数或分数),使得第 i 朵云与第 j 朵云在将来的某一时刻同时覆盖月亮。不同数对 (i,j) 所需的 w 值可以不同。
输入格式
The first line contains three space-separated integers n, l, and wmax (1≤n≤105, 1≤l,wmax≤108) — the number of clouds, the length of each cloud and the maximum wind speed, respectively.
The i-th of the following n lines contains two space-separated integers xi and vi (−108≤xi≤108, vi∈−1,1) — the initial position and the velocity of the i-th cloud, respectively.
The input guarantees that for all 1≤i<j≤n, ∣xi−xj∣≥l.
第一行包含三个以空格分隔的整数 n、l 和 wmax(1≤n≤105,1≤l,wmax≤108),分别表示云的数量、每朵云的长度以及最大风速。
接下来的 n 行中,第 i 行包含两个以空格分隔的整数 xi 和 vi(−108≤xi≤108,vi∈{−1,1}),分别表示第 i 朵云的初始位置和速度。
输入保证:对所有满足 1≤i<j≤n 的 i 和 j,均有 ∣xi−xj∣≥l。
输出格式
Output one integer — the number of unordered pairs of clouds such that it's possible that clouds from each pair cover the moon at the same future moment with a proper choice of wind velocity w.
输出一个整数——满足条件的无序云对的数量:即存在某个合适的风速 w,使得该对中的两朵云在未来某一时刻同时遮住月亮。
输入输出样例
输入#1
5 1 2 -2 1 2 1 3 -1 5 -1 7 -1
输出#1
4
输入#2
4 10 1 -20 1 -10 -1 0 1 10 -1
输出#2
1
说明/提示
In the first example, the initial positions and velocities of clouds are illustrated below.

The pairs are:
- (1,3), covering the moon at time 2.5 with w=−0.4;
- (1,4), covering the moon at time 3.5 with w=−0.6;
- (1,5), covering the moon at time 4.5 with w=−0.7;
- (2,5), covering the moon at time 2.5 with w=−2.
Below is the positions of clouds at time 2.5 with w=−0.4. At this moment, the 1-st and 3-rd clouds both cover the moon.

In the second example, the only pair is (1,4), covering the moon at time 15 with w=0.
Note that all the times and wind velocities given above are just examples among infinitely many choices.
在第一个例子中,云的初始位置和速度如下图所示。

满足条件的云对有:
- (1,3),在时刻 2.5、风速 w=−0.4 时遮蔽月亮;
- (1,4),在时刻 3.5、风速 w=−0.6 时遮蔽月亮;
- (1,5),在时刻 4.5、风速 w=−0.7 时遮蔽月亮;
- (2,5),在时刻 2.5、风速 w=−2 时遮蔽月亮。
下图展示了在时刻 2.5、风速 w=−0.4 时各云的位置。此时,第 1 片云和第 3 片云均遮蔽了月亮。

在第二个例子中,唯一满足条件的云对是 (1,4),它在时刻 15、风速 w=0 时遮蔽月亮。
注意:上述所有给出的时刻和风速值,仅仅是无穷多种可能选择中的若干示例。
输入解题思路,AI测评打分。不知道怎么写?