| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 1024 MB | 137 | 13 | 10 | 7.937% |
The IOI Tower is an extremely tall tower equipped with a staircase for ascending. This staircase consists of $10^{100}$ steps, numbered sequentially from the bottom as step $0$, step $1$, and so on. JOI-kun is currently on step $0$ and intends to climb the staircase. JOI-kun can ascend the staircase by taking the following $2$ types of actions. Descending the staircase is not permitted.
Currently, construction is ongoing at several locations on the staircase, and steps undergoing construction cannot be stepped on. Specifically, there are $N$ ongoing constructions, and the $i$-th construction ($1 ≤ i ≤ N$) is being carried out at steps $L_i , L_{i+1}, \dots , R_i$.
The IOI Tower has $Q$ rooms numbered from $1$ to $Q$. One can enter room $j$ ($1 ≤ j ≤ Q$) from step $X_j$ of the staircase. Therefore, JOI-kun has decided to determine whether he can reach each room and, if possible, how many seconds it will take to reach there in the minimum time.
Given the information about JOI-kun, constructions, and rooms, create a program that determines whether JOI-kun can reach step $X_j$ for each $j$ ($1 ≤ j ≤ Q$) and, if possible, calculates the minimum time it takes.
Read the following data from the standard input.
$N$ $Q$
$D$ $A$ $B$
$L_1$ $R_1$
$L_2$ $R_2$
$\vdots$
$L_N$ $R_N$
$X_1$
$X_2$
$\vdots$
$X_Q$
Output $Q$ lines to the standard output. On the $j$-th line ($1 ≤ j ≤ Q$), output the minimum number of seconds it takes if JOI-kun can reach step $X_j$; otherwise, output -1.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 5 | $R_i ≤ 1\, 000\, 000$ ($1 ≤ i ≤ N$), $X_j ≤ 1\, 000\, 000$ ($1 ≤ j ≤ Q$). |
| 2 | 38 | $N ≤ 2\, 000$, $Q ≤ 2\, 000$. |
| 3 | 25 | $A = 1$, $B = D$. |
| 4 | 32 | No additional constraints. |
3 1 4 10 35 4 5 10 12 14 14 13
120
JOI-kun can reach the $13$th step of the staircase in $120$ seconds following the steps below:
Since it’s not possible to reach the $13$th step of the staircase in less than $120$ seconds, the output is $120$.
This sample input satisfies the constraints of subtasks 1, 2, and 4.
5 10 10 1 9 7 11 25 32 37 38 43 44 50 52 6 12 18 24 30 36 42 48 54 60
6 11 17 22 -1 33 -1 44 -1 55
This sample input satisfies the constraints of subtasks 1, 2, and 4.