No.2650 [Cherry 6th Tune *] Seijaku
Story
This is Sakura Town. Many residents live here, but when the middle of the night comes, the town is wrapped in silence.
Problem Statement
Sakura Town is a town extending in a straight line in the east-west direction, and its length is $A$. In Sakura Town, the point at distance $x$ from the westernmost end is called coordinate $x$.
There are $N$ people in Sakura Town, and the $i~(1 \leq i \leq N)$-th person is at coordinate $X_i$ of the town.
A total of $T$ sounds occurred in Sakura Town. The $t~(1 \leq t \leq T)$-th sound had the following characteristics.
- The time at which this sound occurred is $t$.
- All people at points with coordinates at least $L_t$ and at most $R_t$, and only the people at those coordinates, heard this sound.
For the $N$ people in Sakura Town, answer the following question $i$ for each of $i=1,2, \dots, N$.
- Question $i$: Did the $i$-th person hear at least $1$ of the $T$ sounds that occurred? If so, find the time at which the last sound they heard occurred.
In this problem, assume the following.
- For each integer $t$ between $1$ and $T$, inclusive, at time $t$ all of the $(t-1)$ sounds that occurred earlier can no longer be heard by anyone.
Constraints
- $1 \leq N \leq 10^5$.
- $1 \leq A \leq 10^9$.
- $0 \leq X_i \leq A \quad (i=1,2, \dots, N)$.
- $1 \leq T \leq 10^5$.
- $0 \leq L_t \leq R_t \leq A \quad (t=1,2, \dots, T)$.
- All inputs are integers.
Input
$N$ $A$ $X_1$ $X_2$ $\cdots$ $X_N$ $T$ $L_1$ $R_1$ $L_2$ $R_2$ $\vdots$ $L_T$ $R_T$
Output
The output consists of $N$ lines. On the $i~(1 \leq i \leq N)$-th line, output the answer to question $i$: if the person heard at least $1$ sound, output as an integer the time at which the last sound they heard occurred. If they did not hear even $1$ sound, output -1.
Sample
Sample 1
Input
4 15 3 8 11 14 4 1 6 12 14 7 10 5 9
Output
1 4 -1 2
- Person $1$ heard only the sound that occurred at time $1$. Therefore, the last sound person $1$ heard is the sound that occurred at time $1$.
- Person $2$ heard only the sounds that occurred at times $3,4$. Therefore, the last sound person $2$ heard is the sound that occurred at time $4$.
- Person $3$ did not hear any sound. Therefore,
-1must be output. - Person $4$ heard only the sound that occurred at time $2$. Therefore, the last sound person $4$ heard is the sound that occurred at time $2$.
Sample 2
Input
1 1000000000 500000000 1 499999999 500000001
Output
1
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
Kazun