#FT0000157. Các trạm phát sóng vô tuyến (Radio Stations)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Các trạm phát sóng vô tuyến (Radio Stations)
Radio Stations
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are radio stations at distinct integer positions , with broadcast ranges and frequencies . Stations can reach each other exactly when , so the distance must fit both ranges. An unordered pair is bad when the stations can reach each other and . Count such unordered pairs once each; one-way reachability is not sufficient.
Input
The first line contains . The next lines contain .
Output
Print a 64-bit integer: the number of bad station pairs.
Subtasks
- Subtask 1 (20 points): ; ; ; ; all station coordinates are distinct.
- Subtask 2 (30 points): ; ; ; ; all station coordinates are distinct.
- Subtask 3 (50 points): ; ; ; ; all station coordinates are distinct.
Examples
Example 1
Input
3 2
1 3 10
3 2 5
4 10 8
Output
1
Explanation
Stations 1 and 3 are three units apart, within both ranges 3 and 10, and their frequency difference is . The other pairs differ in frequency by 5 and 3, both above .
Example 2
Input
3 3
1 3 10
3 2 5
4 10 8
Output
2
Explanation
Raising to 3 adds pair 2–3: distance 1 is covered by both ranges and frequency difference is 3. Pair 1–3 still qualifies while 1–2 fails with frequency difference 5.