Editorial for OTHS Coding Competition 3 (Mock CCC) S5 - World Tree
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Subtask 1
This subtask is meant to reward brute-force solutions. One possible approach would be recursively transferring information to a node's children if its capacity is exceeded. This approach will be for updates and
for queries.
Subtask 2
The brute-force solution will be too slow here. Instead, we use the fact that the tree is guaranteed to be a complete binary tree. Thus, it will have a depth of at most . We create a lazy tag for each node and use the same ideas as lazy propagation on a segment tree.
For updates, add information to the node's lazy tag, taking
.
For queries, we propagate the lazy tag on every ancestor of , from top to bottom, taking
. Then, we can access the information at node
.
Subtask 3
The idea is the same as in subtask , but since the tree can now be extremely tall, we cannot propagate the lazy tag on every ancestor of
. Instead, notice that since each node has
or
children, the additional information will either be deleted or halved each time. After halving around
times, the remaining information becomes negligible, since the problem allows for an absolute or relative error of
. Thus, we only need to propagate
nodes directly above
.
Comments
36 times aren't enough. Consider the following testcase:
Or you may use this Java code to generate it:
The correct answer is
1.7763497339728964
, not1
.Yeah... you're right. I forgot to include the
term in my expression. This should hopefully be fixed now.