QOJ.ac

QOJ

Time Limit: 2.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#17246. Apparently Make UTPC

Statistics

畀定正整數序列 $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$、$Y$ 同 $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$
  • 單個輸入入面所有測試數據嘅 $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

說明

  • 喺第一個樣例入面,$C$ 重新排列後可能嘅序列有 $(2, 1, 4, 3)$ 同 $(4, 3, 2, 1)$。輸出字典序最小嘅 $(2, 1, 4, 3)$。
  • 喺第二個樣例入面,$C$ 重新排列後唯一可能嘅序列係 $(4, 3, 2, 1)$。輸出 $(4, 3, 2, 1)$。
  • 喺第三個樣例入面,無法達成目標。輸出 -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.