QOJ.ac

QOJ

Limite de temps : 2.0 s Limite de mémoire : 1024 MB Points totaux : 100 Hackable ✓

#17246. Apparently Make UTPC

Statistiques

給定正整數序列 $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.