QOJ.ac

QOJ

時間限制: 5.0 s 記憶體限制: 512 MB 總分: 100 互動

#11700. $\leq$ 或 $\geq$

统计

这是一个交互式问题。

有 $n$ 个栈,每个栈包含 $k$ 个不超过 $10^9$ 的正整数。你将与评测程序进行一场游戏。最初你只知道每个栈的栈顶元素。游戏过程如下:

  • 在每一轮开始时,你选择一个整数 $x$。
  • 之后,评测程序会选择以下选项之一:“$\le$” 或 “$\ge$”。记所选关系为 $R$。
  • 对于每个非空栈,如果栈顶元素 $t$ 满足不等式 $t \, R \, x$,则 $t$ 会从栈中移除。此操作对每个栈仅执行一次。
  • 最后,你会获知所选的关系 $R$ 以及每个栈的当前状态,即该栈为空,或者该栈的栈顶数字。

在除样例外的所有测试中,$n = 10\,000, k = 10$。你的任务是在不超过 50 次操作内清空所有栈。

注意,评测程序是自适应的,即栈的内容不是固定的,可能会根据你的程序输出而“动态”改变。

交互

输入的第一行包含两个整数 $n, k$,分别表示栈的数量和每个栈的大小。对于样例,$n = 4, k = 2$。在其他所有测试中,$n = 10\,000, k = 10$。

输入的第二行包含 $n$ 个整数,表示每个栈的初始栈顶元素。

在每一轮开始时,你应该输出一个整数 $x$ ($1 \le x \le 10^9$)。

下一行输入将包含一个字符串,该字符串要么是单词 “End”,要么是字符串 “<=” 或 “>=” 之一。

如果是 “End”,你的程序应立即以零退出码终止。如果你的程序成功清空了所有栈,或者进行了错误的查询,或者在 50 次查询后仍有非空栈,都可能会出现这种情况。

否则,该字符串表示所选的关系 $R$,接下来的输入行将包含 $n$ 个整数,每个整数要么是 $0$(如果对应的栈为空),要么是该栈当前的栈顶元素。

栈中的所有值均为不超过 $10^9$ 的正整数。

请确保你的输出没有被缓存,例如在打印每个数字后,在 C/C++ 中调用 fflush(stdout),在 Java 中调用 System.out.flush(),或在 Python 中调用 sys.stdout.flush()

样例

输入 1

4 2
1 2 3 4
<=
5 6 3 4
>=
0 0 3 8
<=
0 0 7 8
<=
0 0 0 8
End

输出 1

2
4
3
7
8

说明

在样例测试中,有四个固定的栈,大小为 2: 1 2 3 4 5 6 7 8

接下来我们描述 “样例” 部分所示的交互过程。请注意,尽管栈是固定的,但系统中的交互器即使在你询问相同查询时,其行为也可能不完全相同。

在第一次查询中,$x = 2$ 且 $R = \text{“}\le\text{”}$。查询后,数字 1 和 2 被移除,栈的状态变为: 3 4 5 6 7 8

在第二次查询中,$x = 4$ 且 $R = \text{“}\ge\text{”}$。数字 5、6 和 4 被移除,栈的状态变为: 3 7 8

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.