#abc273e. E - Notebook
E - Notebook
Score : points
问题描述
我们有一个整数序列 和一本笔记本。该笔记本有 页。
你将收到 个查询请求。每个查询请求属于以下四种类型之一:
ADD $x$: 将整数 $x$ 添加到序列 $A$ 的末尾。
DELETE: 若 $A$ 不为空,则删除 $A$ 的最后一个元素;否则不做任何操作。
SAVE $y$: 擦除笔记本上第 $y$ 页记录的序列,并将当前的 $A$ 序列记录到第 $y$ 页。
LOAD $z$: 用笔记本上第 $z$ 页记录的序列替换当前的 $A$ 序列。
初始时,序列 是空的,且笔记本的每一页都记录着一个空序列。按照给定顺序依次处理这 个查询请求,并在处理完每个查询后打印出 的最后一个元素。
由于输入和输出可能较大,建议使用快速输入输出方法。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
We have an integer sequence and a notebook. The notebook has pages.
You are given queries. Each query is of one of the following four kinds:
ADD $x$: append an integer $x$ to the tail of $A$.
DELETE: remove the last term of $A$ if $A$ is not empty; do nothing otherwise.
SAVE $y$: erase the sequence recorded on the $y$-th page of the notebook, and record the current $A$ onto the $y$-th page.
LOAD $z$: replace $A$ with the sequence recorded on the $z$-th page of the notebook.
Initially, is an empty sequence, and an empty sequence is recorded on each page of the notebook. Process queries successively in the given order and print the last term of after processing each query.
The use of fast input and output methods is recommended because of potentially large input and output.
Constraints
- , , , and are integers.
- Each of the given queries is of one of the four kinds in the Problem Statement.
Input
The input is given from Standard Input in the following format:
Output
For each , let be the last element of after processing up to the -th query, or let if is empty, and print them in the following format:
Sample Input 1
11
ADD 3
SAVE 1
ADD 4
SAVE 2
LOAD 1
DELETE
DELETE
LOAD 2
SAVE 1
LOAD 3
LOAD 1
Sample Output 1
3 3 4 4 3 -1 -1 4 4 -1 4
Initially, is an empty sequence, so , and an empty sequence is recorded on each page of the notebook.
- By the -st query, is appended to the tail of , resulting in .
- By the -nd query, the sequence recorded on the -st page of the notebook becomes . It remains that .
- By the -rd query, is appended to the tail of , resulting in .
- By the -th query, the sequence recorded on the -nd page of the notebook becomes . It remains that .
- By the -th query, is replaced by , which is recorded on the -st page of the notebook, resulting in .
- By the -th query, the last term of is removed, resulting in .
- By the -th query, nothing happens because is already empty. It remains that .
- By the -th query, is replaced by , which is recorded on the -nd page of the notebook, resulting in .
- By the -th query, the sequence recorded on the -st page of the notebook becomes . It remains that .
- By the -th query, is replaced by , which is recorded on the -rd page of the notebook, resulting in .
- By the -th query, is replaced by , which is recorded on the -st page of the notebook, resulting in .
Sample Input 2
21
ADD 4
ADD 3
DELETE
ADD 10
LOAD 7
SAVE 5
SAVE 5
ADD 4
ADD 4
ADD 5
SAVE 5
ADD 2
DELETE
ADD 1
SAVE 5
ADD 7
ADD 8
DELETE
ADD 4
DELETE
LOAD 5
Sample Output 2
4 3 4 10 -1 -1 -1 4 4 5 5 2 5 1 1 7 8 7 4 7 1
update @ 2024/3/10 11:30:41