問題一覧 > 通常問題

No.1675 Strange Minimum Query

レベル : / AI推定難易度 : 1500 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 161
作問者 : stoq / テスター : akakimidori hanyu
お気に入りにしたユーザー ProblemId : 4295 / 自分の提出
問題文最終更新日: 2021-08-07 20:40:23
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 313 (順位表) の他の問題:

Problem Statement

Consider the following problem.

問題文:
長さ $N$ の数列 $A_1, A_2, \cdots, A_N$ があります。次の $Q$ 個のクエリに答えてください。
・ $i$ 個目のクエリでは整数 $l_i, r_i$ が与えられる。 $A_{l_i}, A_{l_i + 1}, \cdots, A_{r_i}$ の最小値を求めよ。

制約:
$1 \leq N,Q \leq 2 \times 10^5$
$1 \leq A_i \leq 10^9 \ (1 \leq i \leq N)$
$1 \leq l_i \leq r_i \leq N \ (1 \leq i \leq Q)$

yuki solved this problem and obtained $B_i$ as the answer to the $i$-th query.

However, after solving the problem, yuki lost the sequence $\{ A_i \}$ and can no longer tell whether the answers are actually correct.

If there exists a sequence $\{ A_i \}$ that satisfies the constraints and for which the answers to all queries match, construct one such sequence; otherwise, output -1.

Input

$N \ Q$
$l_1 \ r_1 \ B_1$
$\vdots$
$l_Q \ r_Q \ B_Q$

  • All inputs are integers.
  • $1 \leq N,Q \leq 2 \times 10^5$
  • $1 \leq B_i \leq 10^9$
  • $1 \leq l_i \leq r_i \leq N$

Output

If there exists a sequence $\{ A_i \}$ of length $N$ consisting of integers between $1$ and $10^9$, inclusive, such that the minimum of $A_{l_i}, A_{l_i + 1}, \cdots, A_{r_i}$ is $B_i$ for every $i \ (1 \leq i \leq Q)$, output one such sequence; otherwise, output -1.

Output the values separated by spaces, followed by a newline at the end (also output a newline in the case of -1).
Note that extra trailing spaces or a missing newline will result in a wrong answer.

Sample

Sample 1
Input
5 3
1 3 1
3 5 3
4 5 4
Output
2 1 3 5 4

The sequence $2,1,3,5,4$ satisfies the conditions for all queries, since

  • the minimum of $A_1,A_2,A_3$ is $1$,
  • the minimum of $A_3,A_4,A_5$ is $3$, and
  • the minimum of $A_4,A_5$ is $4$.

Other sequences also satisfy the conditions; you may output any of them.

Sample 2
Input
3 2
1 2 2
1 1 1
Output
-1
No sequence satisfies the conditions.

Sample 3
Input
4 3
1 3 1
2 4 1
1 4 1
Output
1 1 1 1

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。