問題一覧 > 通常問題

No.2650 [Cherry 6th Tune *] Seijaku

レベル : / AI推定難易度 : 1200 / 実行時間制限 : 1ケース 2.500秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 108
作問者 : 👑 Kazun / テスター : 👑 p-adic
お気に入りにしたユーザー ProblemId : 4751 / 自分の提出
問題文最終更新日: 2024-02-23 21:36:43
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 418 (Re: start!) (順位表) の他の問題:

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, -1 must 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もしくは右上の雲マークをクリックしてアカウントを作成してください。