#6170. [VKOSHP 2024] M-11 Highway
[VKOSHP 2024] M-11 Highway
[VKOSHP 2024] M-11 Highway
题目描述
The new high-speed highway M-11 is an infinite straight line.On the highway, there are stopping points, each of which is a rest area or a gas station. Each stopping point is defined by its coordinate , and no two stopping points are located at the same place. A triplet of stopping points is called if , there are gas stations at points and , a rest area at point , and the distance between the gas stations does not exceed .
A team from Moscow is planning to travel to the contest along the M-11 highway, and its leader became curious about how many convenient triplets of stopping points exist along the way.
输入格式
The first line contains two natural numbers $n$ and $d$ --- the number of stopping points and the maximum distance between gas stations ($3 \leq n \leq 5 \cdot 10^{5}$, $2 \leq d \leq 10^{9}$).In the following lines, the stopping points are given. Each stopping point is defined by two integers and --- the coordinate of the point and its type. Type denotes a rest area, and type denotes a gas station (; ). It is guaranteed that the coordinates of the stopping points are in increasing order.
输出格式
Output a single number --- the number of convenient triplets.8 5
1 1
2 0
3 1
6 0
7 0
8 1
15 1
19 1
3
10 6
0 1
1 0
3 1
4 0
5 1
8 1
10 0
11 0
14 1
18 1
7