Editorial for Back to School '24 P3 - Tournament
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Build a segment tree over the array with the missing student inserted at the beginning. Since is a power of 2, the structure of the segment tree is the same as the structure of a tournament, where each non-leaf node represents a match between two students. At each node of the tree, store two values: the winner of the match (i.e., the maximum skill of any student in the node's subtree) and the sum of the underwhelmingness of all matches played in the node's subtree, denoted as . The segment tree must also support an update operation to modify a value in . The solution for a given array is given by .
To find the answer for all possible positions to insert the missing student, two update operations can be used to swap the missing student with their neighbor to the right, querying after each swap. This process is repeated until the answer has been found for every possible position of the missing student.
Time Complexity:
Comments