#K86212. Digital Garden Growth Management
Digital Garden Growth Management
Digital Garden Growth Management
You are tasked with managing a digital garden where plants grow over time. Each event in the garden is represented in one of the following formats:
- 0 x: Plant a new plant with an initial growth value x.
- 1 i x: Water the plant at index i (1-indexed), increasing its growth value by x (i.e. update: \( garden[i-1] += x \)).
- 2 i x: Prune the plant at index i, decreasing its growth value by x (i.e. update: \( garden[i-1] -= x \)).
- 3 i: Query the current growth value of the plant at index i.
The input terminates when an event "0 0" is encountered (this event is not processed).
Your task is to process all events (except the terminating one) and, for each query event, output the current growth value of the requested plant. Finally, after processing all events, output a line with the string end
.
inputFormat
The input is given from stdin
and has the following format:
n op1 [arg1] [arg2] op2 [arg1] [arg2] ... opn [arg1] [arg2]
The first line contains an integer n representing the number of events. Each of the next n lines contains an event. Each event begins with an operation code:
- 0 x: Plant a new plant with initial growth x. If x is 0, it indicates termination (do not process this event).
- 1 i x: Water the plant at index i (1-indexed) by adding x.
- 2 i x: Prune the plant at index i by subtracting x.
- 3 i: Query the current growth value of the plant at index i.
outputFormat
For each query event, output the growth value of the corresponding plant on a new line. At the end, output a line with the text end
. The output should be printed to stdout
.
9
0 10
0 20
1 1 5
3 1
2 2 10
3 2
0 30
3 3
0 0
15
10
30
end
</p>