QOJ.ac

QOJ

時間限制: 2.0 s 記憶體限制: 1024 MB 總分: 100 可 Hack ✓

#17246. Apparently Make UTPC

统计

Bạn được cho các dãy số nguyên dương $A = (A_1, A_2, \dots, A_X)$, $B = (B_1, B_2, \dots, B_Y)$ và $C = (C_1, C_2, \dots, C_Z)$ có độ dài lần lượt là $X$, $Y$ và $Z$. Ở đây, $X \le Y \le Z$ được thỏa mãn.

Bạn muốn sắp xếp lại các phần tử của $C$ sao cho dãy thu được chứa cả $A$ và $B$ như các dãy con liên tiếp.

Hãy xác định xem có thể đạt được mục tiêu này hay không. Nếu có thể, hãy tìm dãy $C$ có thứ tự từ điển nhỏ nhất sau khi sắp xếp lại.

Bạn được cho $T$ bộ test. Hãy giải quyết từng bộ test.

Dữ liệu vào

Dữ liệu vào được cho từ Đầu vào Chuẩn theo định dạng sau:

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

Mỗi bộ test được cho theo định dạng sau:

$$\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}$$

  • Tất cả các giá trị đầu vào đều là số nguyên.
  • $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$
  • Tổng của $X + Y + Z$ trên tất cả các bộ test trong một dữ liệu vào không vượt quá $4 \times 10^5$.

Kết quả

In ra $T$ dòng. Dòng thứ $i$ chứa -1 nếu không thể đạt được mục tiêu cho bộ test thứ $i$, hoặc dãy $C$ sau khi sắp xếp lại có thứ tự từ điển nhỏ nhất nếu có thể đạt được.

Ví dụ

Dữ liệu vào 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

Kết quả 1

2 1 4 3
4 3 2 1
-1

Giải thích

  • Trong ví dụ thứ nhất, các dãy có thể sau khi sắp xếp lại $C$ là $(2, 1, 4, 3)$ và $(4, 3, 2, 1)$. Hãy in ra $(2, 1, 4, 3)$, là dãy có thứ tự từ điển nhỏ nhất.
  • Trong ví dụ thứ hai, dãy duy nhất có thể sau khi sắp xếp lại $C$ là $(4, 3, 2, 1)$. Hãy in ra $(4, 3, 2, 1)$.
  • Trong ví dụ thứ ba, không thể đạt được mục tiêu. Hãy in ra -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.