#LCA0000024. Trình soạn thảo có hoàn tác nhiều cấp (Editor)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Trình soạn thảo có hoàn tác nhiều cấp (Editor)
Editor
Source: Baltic Olympiad in Informatics
Version: Phuoc Hung OJ Extended
Problem Statement
Byteasar is developing a text editor with multi-level undo. Initially the editor state is the integer . Each operation is one of two types:
- An edit has . It sets the editor state to and has level .
- An undo has . Its level is . It finds the most recent operation that is still active and has level at most , and marks it undone.
Every new operation starts as active. If an undone operation is itself an undo, the operation it had undone must have its active/undone state flipped. The effect propagates until an edit operation is reached.
The editor's current state is the value established by the most recent active edit; if there is none, it is . Every undo operation is guaranteed to find a valid target.
Print the editor state after each operation.
Input
- The first line contains .
- Each of the next lines contains a nonzero integer operation .
Output
Print lines; line contains the current value after operation .
Subtasks
- Subtask 1 (20 points): ; ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
11
1
2
5
-1
-1
-3
4
-2
-1
-1
1
Output
1
2
5
2
1
2
4
2
1
0
1
Explanation
The first operations set values to , then , then . A level- undo returns to , then another level- undo returns to . A level- undo can later return to under the nested-level rule.