#P5471. [NOI2019] 弹跳
[NOI2019] 弹跳
Description
There are cities in Flea Kingdom, numbered from to , and city is the capital. All cities are located on a grid within a area. Each city has integer coordinates , and no two cities share the same coordinates.
There are jumping devices in Flea Kingdom, numbered from to . Device is located in city and has parameters . By using this device, a flea can spend units of time to jump from city to any city whose coordinates satisfy $L_i \leq x \leq R_i, D_i \leq y \leq U_i (1 \leq L_i \leq R_i \leq w, 1 \leq D_i \leq U_i \leq h)$. Note that a city may have multiple jumping devices, or none.
Because cities are far apart, fleas must rely on jumping devices to travel. Specifically, a trip will pass through several cities; the city numbers in order can be written as a sequence . The jumping device numbers used in order can be written as a sequence . Each city may appear in the sequence any number of times, and each jumping device may appear in the sequence any number of times. For each , device is located in city , and the flea can use this device to jump to city . We call this a trip from city to city . It makes jumps in total, and costs units of time.
Now the flea king wants to know, for every city other than the capital (city ), the minimum number of time units needed to start from the capital and reach that city. The king guarantees that for every city, there exists at least one trip from the capital to it.
Input Format
The first line contains four integers . The meanings of the variables are described in the statement.
The next lines: line contains two integers , indicating the coordinates of city .
The next lines: line contains six integers , indicating the city where device is located, the time needed for the jump, and the reachable rectangular region. The meanings of these integers are described in the statement.
Output Format
Output lines. Line contains one integer, representing the minimum number of time units needed to travel from the capital of Flea Kingdom to city .
5 3 5 5
1 1
3 1
4 1
2 2
3 3
1 123 1 5 1 5
1 50 1 5 1 1
3 10 2 2 2 2
50
50
60
123
Hint
More Samples
You can obtain more samples through the additional files.
Sample 2
See jump/jump2.in and jump/jump2.ans in the additional files.
The Constraints for this sample are .
Sample 3
See jump/jump3.in and jump/jump3.ans in the additional files.
The Constraints for this sample are .
Constraints
For all test points and samples:
$1 \leq n \leq 70000 , 1 \leq m \leq 150000 , 1 \leq w, h \leq n , 1 \leq t_i \leq 10000$.
The detailed limits for each test point are shown in the table below.
| Test Point ID | Special Constraints | ||
|---|---|---|---|
| None | |||
| Each jumping device can reach exactly one city, and , | |||
| None | |||
Translated by ChatGPT 5
京公网安备 11011102002149号