Editorial for COCI '20 Contest 1 #5 Tenis
Submitting an official solution before solving the problem yourself is a bannable offence.
We have two types of pairs of players: pairs in which the victory is strict (the best position of the winner (w.r.t. courts) is strictly higher than the best position of the loser), and pairs in which victory is not strict, which means the best positions of the players with respect to courts are equal.
There are at most pairs of the latter type, and thus it is enough to check, for each position from to , whether some such match happens between some of the (at most three) players to whom that position is the best w.r.t. courts. The rest of this description refers to the first set of matches (strict victories).
Each player can be assigned to a basket (bitmask) which indicates the court on which his position is the best. For example, the player whose best court is the third court would go to the basket , and the player whose best courts (with an equal rank) are the first and the second court would go to the basket .
We look for a solution by fixing one player (let's say his best position is ) and choosing another player's basket. We calculate how many players in that the basket beats him strictly. These are the players from this basket whose best position is better than . This can be calculated by binary search on a sorted array of the best player positions in the basket. The court of those matches we can determine from the basket itself, i.e. from the position of the in the bitmask. If the bitmask has two or three 's (equal court winners), we compare positions of a fixed player (the loser) on those courts.
Comments