QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 512 MB Points totaux : 100

#7508. 快速调试器

Statistiques

最近你收到了一台旧电脑。这台旧电脑拥有一个 8 位 CPU,包含四个寄存器:axbxcxdx,并且仅支持一些简单的指令。对于不熟悉汇编语言的人,这里有一份编程指南。

该 CPU 拥有四个 8 位寄存器:axbxcxdx。你可以将它们视为存储 $[0, 255]$ 之间整数的变量。

该 CPU 仅支持三种位运算:按位或(bitwise-or)、按位与(bitwise-and)和按位异或(bitwise-xor)。每种位运算都有两种指令。

类型 1:两个操作数均为寄存器,写作 “or r1 r2”,其中 r1r2 均为寄存器名称 axbxcxdx 之一(r1r2 可以指向同一个寄存器)。该指令将 r1 的值设置为 r1r2 进行按位或运算的结果。(类似地,按位与和按位异或指令写作 “and r1 r2” 和 “xor r1 r2”)。

类型 2:其中一个操作数为立即数,写作 “ori r imm”,其中 r 是寄存器名称 axbxcxdx 之一,imm 是指令中给出的 $[0, 255]$ 之间的常量。该指令将 r 的值设置为 rimm 进行按位或运算的结果。(类似地,按位与和按位异或指令写作 “andi r imm” 和 “xori r imm”)。

该 CPU 不支持循环,但汇编器为程序员实现了一个简单的循环。如果汇编器看到 “repeat m” 语句,它会自动重复循环块中的内容,总共重复 $m$ 次。格式如下所示:

repeat m
<repeat block>
end

这里,$m$ 是语句中给出的 $[2, 255]$ 之间的常量,<repeat block> 由一条或多条语句组成,这些语句可以是位运算指令,也可以是 repeat-end 语句。

现在,你想在你的新笔记本电脑上编写一个比旧电脑快得多的模拟器。你的模拟器将获得一个有效的程序和 $q$ 个查询。每个查询包含五个整数 $k, a_0, b_0, c_0, d_0$。初始时,寄存器被设置为给定的值:ax = $a_0$, bx = $b_0$, cx = $c_0$, dx = $d_0$。你需要输出程序执行 $k$ 条位运算指令后,寄存器 axbxcxdx 的值。

输入格式

第一行包含两个整数 $n$ 和 $q$ ($1 \le n \le 12\,000$; $1 \le q \le 10\,000$),分别表示指令的数量和查询的数量。

接下来 $n$ 行,每行是一条指令。格式如上所述。

接下来的 $q$ 行,每行包含五个整数 $k, a_0, b_0, c_0, d_0$ ($1 \le k \le 10^9$; $0 \le a_0, b_0, c_0, d_0 \le 255$),表示一个查询,要求计算执行 $k$ 次位运算后的寄存器值。保证程序在执行 $k$ 条位运算指令之前不会终止。

输出格式

输出 $q$ 行。第 $i$ 行必须包含四个整数 $a_k, b_k, c_k, d_k$,表示程序执行 $k$ 条位运算指令后寄存器 axbxcxdx 的值。

样例

输入 1

6 2
repeat 5
xor ax bx
xori ax 3
and cx ax
xor cx dx
end
10 1 2 4 3
8 4 1 2 3

输出 1

0 2 2 3
4 1 3 3

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.