ユニークビジョンプログラミングコンテスト2026 夏(AtCoder Regular Contest 226)
D
五队列
Penta-Queue
AtCoder
⌀ 2642
原题
← CE →

五队列AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

This is an interactive problem (in which your program interacts with the judge via input and output).

这是一个交互题(你的程序需要通过输入和输出与评测器进行交互)。AI (CI翻译)

There are five queues numbered $1$ through $5$. Initially, all queues are empty.

有五个编号为 $1$ 至 $5$ 的队列。初始时,所有队列均为空。AI (CI翻译)

The judge gives you the following two types of queries, $Q$ times each, for a total of $2Q$ times.

评测器会分别给出以下两种查询各 $Q$ 次,共 $2Q$ 次。AI (CI翻译)

  • push query: The judge gives you an integer $X$, which is appended to the back of queue $1$. The integers $X$ given in the push queries are all distinct. Then, you may perform the following move operation zero or more times.
  • move operation: Choose integers $i,j$ satisfying $1 \le i,j \le 5$, remove the value at the front of queue $i$, and append it to the back of queue $j$. Here, you cannot choose an empty queue as $i$. It is not required that $i\ne j$.
  • pop query: The judge gives this query only when at least one queue is non-empty. You choose an integer $i$ satisfying $1 \le i \le 5$. At this point, queue $i$ must be non-empty, and the value at its front must be the minimum among all the values currently contained in the five queues. Then, the judge removes the value at the front of queue $i$.
  • push 查询:评测器给出一个整数 $X$,将其追加到队列 $1$ 的末尾。push 查询中给出的整数 $X$ 两两不同。随后,你可以执行下述移动操作零次或多次。
  • 移动操作:选择满足 $1 \le i,j \le 5$ 的整数 $i,j$,从队列 $i$ 的队首取出一个值,并将其追加到队列 $j$ 的末尾。此时,不能选择空队列作为 $i$。不要求 $i\ne j$。
  • pop 查询:仅当至少有一个队列非空时,评测器才会给出此查询。你需要选择满足 $1 \le i \le 5$ 的整数 $i$。此时,队列 $i$ 必须非空,且其队首的值必须是当前五个队列中所有值的最小值。随后,评测器会移除队列 $i$ 的队首值。
AI (CI翻译)

You may perform the move operation at most $10^5$ times in total. Create a program that correctly responds to all queries.

总共最多可以执行 $10^5$ 次移动操作。请编写程序,正确响应所有查询。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $1 \le Q \le 5000$
  • $1 \le X \le 10^9$
  • The values $X$ appended in the push queries are all distinct.
  • The push query and the pop query are each given $Q$ times.
  • At the time each pop query is given, at least one queue is non-empty.
  • All input values are integers.
  • $1 \le Q \le 5000$
  • $1 \le X \le 10^9$
  • push 查询中追加的值 $X$ 两两不同。
  • push 查询和 pop 查询各给出 $Q$ 次。
  • 每次给出 pop 查询时,至少有一个队列非空。
  • 所有输入值均为整数。
AI (CI翻译)

Interaction

交互

AI (CI翻译)

This problem is interactive.

这是一个交互题。AI (CI翻译)

First, the judge gives a positive integer $Q$ in the following format:

首先,评测器按照以下格式给出一个正整数 $Q$:AI (CI翻译)

Q

Q
AI (CI翻译)

Then, perform the following interaction $2Q$ times. In each round, the judge first gives a push query or a pop query.

然后,进行以下交互,共 $2Q$ 轮。在每一轮中,评测器首先给出一个 push 查询或 pop 查询。AI (CI翻译)

A push query is given in the following format:

push 查询的格式如下:AI (CI翻译)

1 X

1 X
AI (CI翻译)

A pop query is given in the following format:

pop 查询的格式如下:AI (CI翻译)

2

2
AI (CI翻译)

(If your response to the previous query was invalid, -1 will be given from Standard Input instead of a query. In this case, immediately terminate your program normally. However, if your first invalid output is your response to the $2Q$-th query, no further input will be given after that.)

(如果你对上一个查询的响应无效,则标准输入中会给出 -1,而不是查询。此时,请立即正常终止程序。但是,如果你的第一次无效输出是对第 $2Q$ 个查询的响应,则之后不会再给出输入。)AI (CI翻译)

If a push query is given, let $k$ be the number of move operations you perform, and let $i_r,j_r$ be the queue numbers chosen in the $r$-th move operation; output $k+1$ lines in the following format. Be sure to add a newline at the end of the output.

如果给出 push 查询,设你执行的移动操作次数为 $k$,第 $r$ 次移动操作中选择的队列编号为 $i_r,j_r$;请按照以下格式输出 $k+1$ 行。请务必在输出末尾添加换行符。AI (CI翻译)

k
i_1 j_1
i_2 j_2
\vdots
i_k j_k

k
i_1 j_1
i_2 j_2
\vdots
i_k j_k
AI (CI翻译)

If a pop query is given, output the number $i$ of the queue from which to remove the front value, in the following format. Be sure to add a newline at the end of the output.

如果给出 pop 查询,请按照以下格式输出要移除队首值的队列编号 $i$。请务必在输出末尾添加换行符。AI (CI翻译)

i

i
AI (CI翻译)

Note

说明

AI (CI翻译)
  • Each time you output a response to a query, flush Standard Output after adding a newline at the end. Otherwise, the judge result may be TLE.
  • If you receive -1 as input from the judge, immediately terminate your program normally. If you do so, the judge result will be WA; otherwise, the judge result is indeterminate.
  • Extra newlines are regarded as malformed output, so do not output them.
  • After you finish responding to the $2Q$ queries, immediately terminate your program. Otherwise, the judge result will be indeterminate.
  • The judge for this problem is not adaptive. Before the interaction begins, the judge determines the types and order of the queries, and the integer $X$ given in each push query.
  • 每次对查询输出响应后,都应在末尾添加换行符并刷新标准输出。否则,评测结果可能为 TLE。
  • 如果从评测器处收到 -1,请立即正常终止程序。如果这样做,评测结果将为 WA;否则,评测结果是不确定的。
  • 多余的换行符会被视为格式错误的输出,因此不要输出多余的换行符。
  • 完成对 $2Q$ 个查询的响应后,请立即终止程序。否则,评测结果将是不确定的。
  • 本题的评测器不是自适应的。在交互开始前,评测器就会确定查询的类型和顺序,以及每个 push 查询中给出的整数 $X$。
AI (CI翻译)

Sample Interaction

样例交互

AI (CI翻译)

Below is a case where $Q=2$, and the judge appends the values $5,3$ in this order.

以下是 $Q=2$,且评测器按此顺序追加值 $5,3$ 的情况。AI (CI翻译)

Input Output Description
2 $Q$ is given.
1 5 A push query. $X=5$ is given, and it is appended to the back of queue $1$.
0 Perform zero move operations.
1 3 A push query. $X=3$ is given, and it is appended to the back of queue $1$.
3 1 2 1 2 2 2 Perform three move operations. Move $5$ to queue $2$, move $3$ to queue $2$, and move the front value $5$ of queue $2$ to the back of the same queue. As a result, queue $2$ contains $3,5$ from front to back.
2 A pop query.
2 Choose queue $2$. Then, the judge removes the front value $3$ of queue $2$.
2 A pop query.
2 Choose queue $2$. Then, the judge removes the front value $5$ of queue $2$.
输入 输出 说明
2 给出 $Q$。
1 5 push 查询。给出 $X=5$,并将其追加到队列 $1$ 的末尾。
0 执行零次移动操作。
1 3 push 查询。给出 $X=3$,并将其追加到队列 $1$ 的末尾。
3 1 2 1 2 2 2 执行三次移动操作。将 $5$ 移动到队列 $2$,将 $3$ 移动到队列 $2$,再将队列 $2$ 的队首值 $5$ 移动到同一队列的末尾。这样,队列 $2$ 从队首到队尾依次为 $3,5$。
2 pop 查询。
2 选择队列 $2$。随后,评测器移除队列 $2$ 的队首值 $3$。
2 pop 查询。
2 选择队列 $2$。随后,评测器移除队列 $2$ 的队首值 $5$。
AI (CI翻译)
题目信息

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。