#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 ss 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, tt tunnels were built along the route. Tunnel ii starts at aia_i kilometers from Zurich and ends at bib_i kilometers. (So the length of tunnel ii is biaib_i-a_i.)

You are given a train timetable between the two cities. There are mm trains from Zurich to Lugano; train jj departs at minute cjc_j. There are nn trains from Lugano to Zurich; train kk departs at minute dkd_k. All trains in operation, regardless of direction and whether they are inside a tunnel, travel at a constant speed of 11 kilometer per minute. There are no stations along the route, and trains do not stop at signals. Therefore, each train takes exactly ss 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^\dagger inside a tunnel, a collision occurs.

Given the tunnel information and the train timetable, determine whether a collision will occur.

^\daggerStrictly: as stated in the original text (strictly).

Input Format

The first line contains four integers s,t,m,ns,t,m,n — the railway length, the number of tunnels, and the numbers of trains departing from Zurich and Lugano.

The second line contains tt integers aia_i — the start point of each tunnel.

The third line contains tt integers bib_i — the end point of each tunnel.

The fourth line contains mm integers cjc_j — the departure times from Zurich.

The fifth line contains nn integers dkd_k — 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 11 Explanation

On a railway of length 100100 kilometers, there are two tunnels: from 2020 to 3030 kilometers from Zurich, and from 5050 to 6060 kilometers from Zurich. The only train departing from Zurich avoids all trains departing from Lugano, as follows:

  • It meets the first train at 55 kilometers from Zurich.
  • It meets the second train between the two tunnels.
  • It meets the third train at 1010 kilometers from Lugano.
  • The fourth train departs long after this train has arrived.

Sample 22 Explanation

Two trains collide in the middle of the only tunnel.


Sample 33 Explanation

Two trains meet near the Zurich end of the tunnel.


Sample 44 Explanation

Two trains meet near the Lugano end of the tunnel.


Constraints

For all testdata, 1s1091\le s\le 10^9, 0t1050\le t\le 10^5, 0m,n2×1030\le m,n\le 2\times 10^3, 0ai<s0\le a_i < s, 0<bis0 < b_i\le s, ai<bia_i < b_i, bi<ai+1b_i < a_{i+1}, 0cj,dk1090\le c_j,d_k\le 10^9, cj<cj+1c_j < c_{j+1}, dk<dk+1d_k < d_{k+1}.

In the first three subtasks, it is guaranteed that s,cj,dks,c_j,d_k are all even.

  • Subtask 1 (1414 points): t,m,n100t,m,n\le 100, s5×103s\le 5\times 10^3.
  • Subtask 2 (1616 points): t5×103t\le 5\times 10^3, s106s\le 10^6.
  • Subtask 3 (4141 points): No additional constraints.
  • Subtask 4 (2929 points): No additional constraints. In addition, s,cj,dks,c_j,d_k are not necessarily even.

Translated by ChatGPT 5