CF762E.Radio stations
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
In the lattice points of the coordinate line there are n radio stations, the i-th of which is described by three integers:
- x__i — the coordinate of the i-th station on the line,
- r__i — the broadcasting range of the i-th station,
- f__i — the broadcasting frequency of the i-th station.
We will say that two radio stations with numbers i and j reach each other, if the broadcasting range of each of them is more or equal to the distance between them. In other words min(r__i, r__j) ≥ |x__i - x__j|.
Let's call a pair of radio stations (i, j) bad if i < j, stations i and j reach each other and they are close in frequency, that is, |f__i - f__j| ≤ k.
Find the number of bad pairs of radio stations.
在坐标轴的格点上有 n 个广播电台,其中第 i 个电台由三个整数描述:
- x__i — 第 i 个电台在坐标轴上的位置(坐标),
- r__i — 第 i 个电台的广播覆盖半径,
- f__i — 第 i 个电台的广播频率。
我们称编号为 i 和 j 的两个广播电台相互可达,当且仅当它们各自的广播半径均不小于二者之间的距离。换言之,满足
min(ri,rj)≥∣xi−xj∣.
若一对广播电台 (i, j) 满足:i < j,且电台 i 与 j 相互可达,且它们的频率接近(即满足 ∣fi−fj∣≤k),则称该对为坏对(bad pair)。
请计算坏对的总数。
输入格式
The first line contains two integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 10) — the number of radio stations and the maximum difference in the frequencies for the pair of stations that reach each other to be considered bad.
In the next n lines follow the descriptions of radio stations. Each line contains three integers x__i, r__i and f__i (1 ≤ x__i, r__i ≤ 109, 1 ≤ f__i ≤ 104) — the coordinate of the i-th radio station, it's broadcasting range and it's broadcasting frequency. No two radio stations will share a coordinate.
第一行包含两个整数 n 和 k(1≤n≤105,0≤k≤10)——分别表示广播电台的数量,以及一对能够相互覆盖的电台其频率之差的最大允许值;若超过该值,则称这对电台为“不良对”。
接下来的 n 行描述了各个广播电台。每行包含三个整数 xi、ri 和 fi(1≤xi,ri≤109,1≤fi≤104)——分别表示第 i 个广播电台的坐标、广播覆盖半径及其广播频率。任意两个广播电台的坐标均不相同。
输出格式
Output the number of bad pairs of radio stations.
输出坏的广播电台对的数量。
输入输出样例
输入#1
3 2 1 3 10 3 2 5 4 10 8
输出#1
1
输入#2
3 3 1 3 10 3 2 5 4 10 8
输出#2
2
输入#3
5 1 1 3 2 2 2 4 3 2 1 4 2 1 5 3 3
输出#3
2
输入#4
5 1 1 5 2 2 5 4 3 5 1 4 5 1 5 5 3
输出#4
5
输入解题思路,AI测评打分。不知道怎么写?