QOJ.ac

QOJ

Süre Sınırı: 2.0 s Bellek Sınırı: 1024 MB Toplam puan: 100 Hack'lenebilir ✓

#17246. Apparently Make UTPC

İstatistikler

กำหนดลำดับของจำนวนเต็มบวก $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$ เป็นลำดับย่อยที่ติดกัน (contiguous subsequences)

จงพิจารณาว่าเป็นไปได้หรือไม่ที่จะบรรลุเป้าหมายนี้ หากเป็นไปได้ จงหาลำดับ $C$ ที่มีอันดับตามพจนานุกรม (lexicographically) น้อยที่สุดหลังจากการจัดเรียงใหม่

คุณจะได้รับชุดทดสอบ $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$ ควรมี -1 หากไม่สามารถบรรลุเป้าหมายสำหรับชุดทดสอบที่ $i$ ได้ หรือพิมพ์ลำดับ $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.