#BS0000219. Mảng lưu phiên bản (Snapshot Array)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Mảng lưu phiên bản (Snapshot Array)
Snapshot Array
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
An array of length has indices through and initially contains zeros. Operations may modify the current array, save its state as a snapshot, or read an entry from a saved snapshot. Later modifications never affect saved states. Snapshot identifiers start at 0 and increase by one with each save. Process the operations in order.
Input
The first line contains . Each of the next lines has one of these forms:
1 i v: assign to current entry .2: save the current state and return its new snapshot identifier.3 i s: read entry from snapshot .
Output
For each operation of type 2 or 3, print the returned identifier or value on its own line. Type 1 produces no output.
Subtasks
- Subtask 1 (20 points): ; ; ; , where counts earlier type-2 operations; only the three specified operation types occur.
- Subtask 2 (30 points): ; ; ; ; , where counts earlier type-2 operations; only the three specified operation types occur.
- Subtask 3 (50 points): ; ; ; , where counts earlier type-2 operations; only the three specified operation types occur.
Examples
Input
3 7
1 0 5
2
1 0 6
3 0 0
2
3 0 1
3 2 1
Output
0
5
1
6
0
Explanation
Save (5,0,0) as snapshot 0. Updating entry 0 to 6 leaves the saved value 5 unchanged. Save (6,0,0) as snapshot 1; reading entries 0 and 2 from it gives 6 and 0.