Mural Time-Lapse
Medium · design
A street artist paints a long wall made of cells cells in a row, numbered 0 to cells - 1. Every cell starts with colour 0 (bare wall). You are given a list of operations. operations[i] is one of "paint", "save", "wipe" or "look", and args[i] holds its arguments: [cell, colour] for a "paint", [] (empty) for a "save" or a "wipe", and [cell, photo] for a "look".
"paint"givescellthe colourcolour."save"takes a photo of the whole wall as it is right now. Photos are numbered from0in the order they are taken. The answer to a"save"is the number of the photo it just took."wipe"paints every cell on the wall back to colour0. Photos that were already taken do not change."look"asks for the colour thatcellhad in photo numberphoto. A"look"only ever names a photo that has already been taken.
Return a list with the answer to every "save" and every "look", in the order they appear.
Examples
Example 1
Input: cells = 3, operations = ["paint", "save", "paint", "save", "look", "look", "look"], args = [[0, 5], [], [0, 8], [], [0, 0], [0, 1], [1, 1]]
Output: [0, 1, 5, 8, 0]
The two saves answer 0 and 1. Photo 0 shows cell 0 as 5, photo 1 shows it as 8, and cell 1 was never painted.
Example 2
Input: cells = 2, operations = ["paint", "paint", "save", "wipe", "save", "paint", "save", "look", "look", "look"], args = [[0, 4], [1, 6], [], [], [], [1, 9], [], [1, 0], [1, 1], [1, 2]]
Output: [0, 1, 2, 6, 0, 9]
The three saves answer 0, 1 and 2. Photo 0 shows cell 1 as 6. The wipe sets both cells back to 0, so photo 1 shows 0. Photo 2 is taken after cell 1 was painted 9.
Constraints
- 1 <= cells <= 10^5
- 1 <= len(operations) <= 5 * 10^4
- len(args) == len(operations)
- operations[i] is paint, save, wipe or look
- 0 <= cell < cells
- 0 <= colour <= 10^9
- In a look, 0 <= photo < the number of photos taken before it