#P9314. [EGOI 2021] Railway / 瑞士铁路
[EGOI 2021] Railway / 瑞士铁路
Background
Day 2 Problem B.
This statement is translated from EGOI2021 railway.
Problem Description
There is a railway of length kilometers connecting Zurich and Lugano. The railway passes through the beautiful Alps, creating magnificent scenery along the journey. Since some mountain passes are too high for the railway, tunnels were built along the route. Tunnel starts at kilometers from Zurich and ends at kilometers. (So the length of tunnel is .)
You are given a train timetable between the two cities. There are trains from Zurich to Lugano; train departs at minute . There are trains from Lugano to Zurich; train departs at minute . All trains in operation, regardless of direction and whether they are inside a tunnel, travel at a constant speed of kilometer per minute. There are no stations along the route, and trains do not stop at signals. Therefore, each train takes exactly minutes to reach its destination.
Compared with the length of the railway, the length of a train can be ignored. So in this problem, assume each train is a point moving along the railway.
Normally, the railway has two tracks: one for each direction. The only exception is tunnels. Each tunnel has only one track and can be used in either direction.
At any time, if two trains traveling in opposite directions meet outside a tunnel, they can always pass each other safely. This also includes the case where they meet exactly at an endpoint of a tunnel. However, if two trains traveling in opposite directions meet strictly inside a tunnel, a collision occurs.
Given the tunnel information and the train timetable, determine whether a collision will occur.
Strictly: as stated in the original text (strictly).
Input Format
The first line contains four integers — the railway length, the number of tunnels, and the numbers of trains departing from Zurich and Lugano.
The second line contains integers — the start point of each tunnel.
The third line contains integers — the end point of each tunnel.
The fourth line contains integers — the departure times from Zurich.
The fifth line contains integers — the departure times from Lugano.
Output Format
Output one line containing a string YES or NO, indicating whether a collision will occur.
100 2 1 4
20 50
30 60
120
30 100 200 250
NO
1000 1 1 1
600
700
100
400
YES
1000 1 1 1
600
700
100
300
NO
1000 1 1 1
600
700
100
500
NO
Hint
Sample Explanation
On a railway of length kilometers, there are two tunnels: from to kilometers from Zurich, and from to kilometers from Zurich. The only train departing from Zurich avoids all trains departing from Lugano, as follows:
- It meets the first train at kilometers from Zurich.
- It meets the second train between the two tunnels.
- It meets the third train at kilometers from Lugano.
- The fourth train departs long after this train has arrived.
Sample Explanation
Two trains collide in the middle of the only tunnel.
Sample Explanation
Two trains meet near the Zurich end of the tunnel.
Sample Explanation
Two trains meet near the Lugano end of the tunnel.
Constraints
For all testdata, , , , , , , , , , .
In the first three subtasks, it is guaranteed that are all even.
- Subtask 1 ( points): , .
- Subtask 2 ( points): , .
- Subtask 3 ( points): No additional constraints.
- Subtask 4 ( points): No additional constraints. In addition, are not necessarily even.
Translated by ChatGPT 5