atcoder#ABC273E. [ABC273E] Notebook
[ABC273E] Notebook
Score : points
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:
11
ADD 3
SAVE 1
ADD 4
SAVE 2
LOAD 1
DELETE
DELETE
LOAD 2
SAVE 1
LOAD 3
LOAD 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 .
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
4 3 4 10 -1 -1 -1 4 4 5 5 2 5 1 1 7 8 7 4 7 1