While wandering through a forest, you have stumbled upon a mysterious dynamic apple tree! This tree can be thought of as a set
You will pick a junction and collect all apples from the root up to, and including the junction you stop at, before climbing back down the tree. Unfortunately for you,
There is exactly one apple at each junction, but since this is a dynamic tree, it has a special property where each apple regrows exactly
Every minute, one of your friends (or you) will climb up the tree, collect some apples, and climb back down the tree. They will go in order of their number from
Constraints
For this question, Python users are recommended to use CPython over PyPy.
For this problem, you will be required to pass all the samples in order to receive any points. In addition, you must pass all previous subtasks to earn points for a specific subtask.
Subtask | Points | |
---|---|---|
For all subtasks:
Input Specification
The first line contains 3 integers,
The last line contains
Output Specification
This problem is graded with an identical
checker. This includes whitespace characters. Ensure that every line of output is terminated with a \n
character and that there are no trailing spaces.
Output a single line containing
Sample Input
6 3 2
1 2 2 3 3
Sample Output
4 1 4
Sample Explanation
At the first minute, person
At the second minute, person
At the third minute, the apples at junctions
Comments
SPOILER ALERT
I am so happy that I finally solved it with Segment Tree + lazy. This problem is a really good one to practice Segment tree in a graph. I would recommend to you guys that already solved it in other ways to give it a try!