#P4632. [APIO2018] 新家
[APIO2018] 新家
Description
Wufu Street is a straight road. It can be seen as a number line, and the coordinate of each building on the street can be represented by an integer. Xiaoming is a time traveler. He knows that on this street, there are shops that appear in the past, present, and future. The -th shop can be described by four integers , which represent: the shop’s coordinate, the shop’s type, the year it opens, and the year it closes.
Xiaoming wants to time travel to choose a suitable time and live somewhere on Wufu Street. He provides a list of possible choices containing queries, and each query is represented by a pair (coordinate, time). The -th pair is described by two integers , representing the chosen location and the year .
Now, he wants to compute the quality of life for living at these times and locations. He defines the inconvenience index of living as: in the year of living, the distance from the living point to the shop type that is farthest away. The distance from shops of type to the living point is defined as: in the specified year, among all open shops of type , the distance from the living point to the nearest one. We say shop is open in year if and only if . Note that in some years, not all of the types of shops may have at least one shop open on Wufu Street. In this case, the inconvenience index is defined as .
Your task is to help Xiaoming compute the inconvenience index for each (coordinate, time) pair.
Input Format
The first line contains three integers , representing the number of shops, the number of shop types, and the number of (coordinate, time) pairs. .
The next lines each contain four integers describing a shop, with meanings as stated above. $(1 \le x_i, a_i, b_i \le 10^8, 1 \le t_i \le k, a_i \le b_i)$.
The next lines each contain two integers , representing a (coordinate, time) query. .
Output Format
Output one line containing integers, in order, representing the answers for the (coordinate, time) queries.
4 2 4
3 1 1 10
9 2 2 4
7 2 5 7
4 1 8 10
5 3
5 6
5 9
1 10
4
2
-1
-1
2 1 3
1 1 1 4
1 1 2 6
1 3
1 5
1 7
0
0
-1
1 1 1
100000000 1 1 1
1 1
99999999
Hint
Hint
In the first sample, there are 4 shops, 2 types, and 4 queries.
- For the first query: Xiaoming lives at coordinate 5 in year 3. In this year, shops 1 and 2 are open. The distance to shop 1 is 2, and the distance to shop 2 is 4, so the maximum distance is .
- For the second query: Xiaoming lives at coordinate 5 in year 6. In this year, shops 1 and 3 are open. The distance to shop 1 is 2, and the distance to shop 3 is 2, so the maximum distance is .
- For the third query: Xiaoming lives at coordinate 5 in year 9. In this year, shops 1 and 4 are open. Both are type 1, and there is no open shop of type 2, so the answer is .
- The same situation occurs in the fourth query.
In the second sample, there are 2 shops, 1 type, and 3 queries. Both shops are type 1. In all queries, Xiaoming lives at coordinate 1. In the first two queries, at least one shop is open, so the answer is . In the third query, neither shop is open, so the answer is .
In the third sample, there is 1 shop and 1 query, and the distance between them is .
Subtasks
- Subtask 1 (points: ): .
- Subtask 2 (points: ): .
- Subtask 3 (points: ): , and for all shops .
- Subtask 4 (points: ): , and for all shops .
- Subtask 5 (points: ): .
- Subtask 6 (points: ): .
Translated by ChatGPT 5
京公网安备 11011102002149号