Universal Cup Judging System

Universal Cup

Time Limit: 2.0 s Memory Limit: 512 MB Total points: 100 Communication
Statistics

这是一个“运行两次”的问题。

你有一个包含 $n \le 1000$ 个无符号 64 位整数的数组。你想要将其快速传输到另一台计算机。为此,你通过互联网并行发送这些数字,然后重新组装数组。

然而,出现了一个意外的问题。众所周知,多字节数字的“网络”字节序与现代计算机中使用的顺序不同。具体来说,在现代计算机中,字节是从最低有效位到最高有效位书写的(小端序),而在网络字节序中,字节是从最高有效位到最低有效位书写的(大端序)。在转换过程中,每个数字被写成 8 个字节的序列,且字节顺序被反转。在某些情况下,由于服务器故障,反向转换没有执行……

因此,你发送一个数组,然后接收另一个数组,其中每个元素可能以通常的小端序到达,也可能以网络大端序到达。数组元素的顺序保持不变。在传输时,你最多可以使用 1024 个 64 位整数(换句话说,不超过 8 kibibytes)。你的任务是在可能发生变化后恢复原始数组。

输入格式

如果你需要传输数组,第一行包含单词 “encode”,第二行包含一个整数 $n$ ($1 \le n \le 1000$),第三行包含 $n$ 个范围在 $0$ 到 $2^{64} - 1$ 之间的整数。

如果你需要接收数组,第一行包含单词 “decode”,第二行包含一个整数 $k$ ($k \le 1024$),第三行包含 $k$ 个范围在 $0$ 到 $2^{64} - 1$ 之间的整数。保证数字的顺序与传输时相同,并且每个数字要么是未更改传输的,要么是字节序被反转的(根据题目描述)。

输出格式

在传输数组的情况下,第一行输出一个整数 $k \le 1024$:要传输的整数个数。第二行输出 $k$ 个范围在 $0$ 到 $2^{64} - 1$ 之间的整数。

在接收数组的情况下,单行输出 $n$ 个整数:原始数组。

样例

样例输入 1

encode
3
15 10 2023

样例输出 1

6
15 15 10 10 2023 2023

样例输入 2

decode
6
15 15 10 720575940379279360
16647274547598327808 2023

样例输出 2

15 10 2023

说明

在下方的样例中,在接收数组的情况下,所有六个数字都将在一行中给出。为了可读性,添加了一个额外的换行符。

在每个测试中,你的程序将运行两次:第一次用于传输数组,第二次用于接收它。第一次运行的输出(可能包含变化)将作为第二次运行的输入。如果原始数组被正确恢复,你的解决方案即通过测试。

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.