#SP0000254. Những người du lịch (Tourists)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Những người du lịch (Tourists)
Tourists
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A park has two parallel walking paths on the lines and . For each pair of tourists, the two people simultaneously depart from and at time , walking in the positive direction at speed distance unit per second. Thus both tourists are at height after seconds.
There are walls. Wall is the closed line segment from to ; it appears instantaneously at time and remains present thereafter. Walls may overlap or coincide.
The two tourists cannot see each other whenever the segment connecting their current positions intersects at least one wall already present, including touching an endpoint. For each departure time , find the total duration in seconds for which the two tourists cannot see each other. Each pair of tourists is treated independently; all walls follow the same appearance schedule.
Input
The first line contains two integers , the numbers of tourist pairs and walls.
Each of the next lines contains three integers , describing the vertical endpoints and appearance time of wall .
The last line contains exactly distinct, strictly increasing departure times .
Output
Print exactly lines, one 64-bit integer per line: the total duration of invisibility for the pair departing at , in the order .
Subtasks
- Subtask 1 (20 points): ; ; ; for all ; .
- Subtask 2 (30 points): ; ; ; for all ; .
- Subtask 3 (50 points): ; ; ; for all ; .
Examples
Input
2 2
1 4 3
3 6 5
0 1
Output
2
4
Explanation
There are two walls: appears at time , and at time .
- For departure time , the tourists reach height at time and the first wall blocks their view until they pass height , for second. At time they are at height ; the second wall blocks their view until height , for another second. The answer is .
- For , the tourists reach height at time . The first wall blocks heights from through , for seconds. At time they reach height , and the second wall blocks their view until height , for another seconds. The answer is .
The inclusion of interval endpoints does not affect duration.