The sky can be seen as a one-dimensional axis. The moon is at the origin whose coordinate is 00.
There are nn clouds floating in the sky. Each cloud has the same length ll. The ii-th initially covers the range of (xi,xi+l)(xi,xi+l) (endpoints excluded). Initially, it moves at a velocity of vivi, which equals either 11 or −1−1.
Furthermore, no pair of clouds intersect initially, that is, for all 1≤i<j≤n1≤i<j≤n, |xi−xj|≥l|xi−xj|≥l.
With a wind velocity of ww, the velocity of the ii-th cloud becomes vi+wvi+w. That is, its coordinate increases by vi+wvi+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) (i<ji<j), such that with a proper choice of wind velocity ww not exceeding wmaxwmax in absolute value (possibly negative and/or fractional), the ii-th and jj-th clouds both cover the moon at the same future moment. This wwdoesn't need to be the same across different pairs.
The first line contains three space-separated integers nn, ll, and wmaxwmax (1≤n≤1051≤n≤105, 1≤l,wmax≤1081≤l,wmax≤108) — the number of clouds, the length of each cloud and the maximum wind speed, respectively.
The ii-th of the following nn lines contains two space-separated integers xixi and vivi (−108≤xi≤108−108≤xi≤108, vi∈{−1,1}vi∈{−1,1}) — the initial position and the velocity of the ii-th cloud, respectively.
The input guarantees that for all 1≤i<j≤n1≤i<j≤n, |xi−xj|≥l|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 ww.
5 1 2 -2 1 2 1 3 -1 5 -1 7 -1
4
4 10 1 -20 1 -10 -1 0 1 10 -1
1
In the first example, the initial positions and velocities of clouds are illustrated below.
The pairs are:
- (1,3)(1,3), covering the moon at time 2.52.5 with w=−0.4w=−0.4;
- (1,4)(1,4), covering the moon at time 3.53.5 with w=−0.6w=−0.6;
- (1,5)(1,5), covering the moon at time 4.54.5 with w=−0.7w=−0.7;
- (2,5)(2,5), covering the moon at time 2.52.5 with w=−2w=−2.
Below is the positions of clouds at time 2.52.5 with w=−0.4w=−0.4. At this moment, the 11-st and 33-rd clouds both cover the moon.
In the second example, the only pair is (1,4)(1,4), covering the moon at time 1515 with w=0w=0.
Note that all the times and wind velocities given above are just examples among infinitely many choices.
思路上大体上就是二分了,显然只有初始速度方向相反的云才能相遇,所以猜测应该就是将方向不同的云记录在两个数组里,然后枚举其中一个,二分另一个。然而应该用什么指标来判断云是否能相遇呢?到这儿骚操作就来了,我们想象没有风在吹,月亮自己在跑,如下图。
橙色代表月亮的轨迹,蓝色代表云的轨迹。如果两个蓝条能在橙色部分相遇,那么就说明有一对云是符合要求的。根据w必定大于1,可知橙色线和横轴夹角不得大于45°。那就保证蓝条相交得到的菱形,上面的顶点在橙色区域里,因此xj−xi+l2>|xj−xi+l2+xi|/w。
从第一个满足这个条件的云开始,往后的云都满足这个条件,我们把它加在结果里。
代码奇丑无比,不贴了。