QOJ.ac

QOJ

Límite de tiempo: 2.0 s Límite de memoria: 1024 MB Puntuación total: 100 Hackeable ✓

#17246. Apparently Make UTPC

Estadísticas

それぞれ長さ $X$, $Y$, $Z$ の正整数列 $A = (A_1, A_2, \dots, A_X)$, $B = (B_1, B_2, \dots, B_Y)$, $C = (C_1, C_2, \dots, C_Z)$ が与えられます。ここで、$X \le Y \le Z$ が成り立ちます。

あなたは $C$ の要素を並び替えることで、並び替え後の列が $A$ と $B$ の両方を連続部分列として含むようにしたいと考えています。

この目的を達成できるかどうかを判定してください。達成可能な場合は、並び替え後の列 $C$ として辞書順で最小のものを求めてください。

$T$ 個のテストケースが与えられます。それぞれについて解いてください。

入力

入力は以下の形式で標準入力から与えられます:

$$\begin{aligned} &T \\ &\text{case}_1 \\ &\text{case}_2 \\ &\vdots \\ &\text{case}_T \end{aligned}$$

各テストケースは以下の形式で与えられます:

$$\begin{aligned} &X \ Y \ Z \\ &A_1 \ A_2 \ \dots \ A_X \\ &B_1 \ B_2 \ \dots \ B_Y \\ &C_1 \ C_2 \ \dots \ C_Z \end{aligned}$$

  • 入力される値はすべて整数である。
  • $1 \le T \le 10^5$
  • $1 \le X \le Y \le Z \le 2 \times 10^5$
  • $1 \le A_i \le Z$
  • $1 \le B_i \le Z$
  • $1 \le C_i \le Z$
  • $1$ つの入力ファイルにおけるすべてのテストケースにわたる $X + Y + Z$ の総和は $4 \times 10^5$ 以下である。

出力

$T$ 行出力してください。$i$ 行目には、$i$ 番目のテストケースで目的を達成できない場合は -1 を、達成できる場合は並び替え後の $C$ のうち辞書順で最小のものを出力してください。

入出力例

入力例 1

3
2 2 4
4 3
2 1
4 3 2 1
2 3 4
4 3
3 2 1
4 3 2 1
3 3 3
1 1 1
2 2 2
3 3 3

出力例 1

2 1 4 3
4 3 2 1
-1

注記

  • $1$ 番目の例では、並び替え後の $C$ としてあり得る列は $(2, 1, 4, 3)$ と $(4, 3, 2, 1)$ です。辞書順で最小である $(2, 1, 4, 3)$ を出力します。
  • $2$ 番目の例では、並び替え後の $C$ としてあり得る唯一の列は $(4, 3, 2, 1)$ です。$(4, 3, 2, 1)$ を出力します。
  • $3$ 番目の例では、目的を達成することはできません。-1 を出力します。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#2918EditorialOpenHashc20262110View
#1405EditorialOpen题解jianglyView

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.