Editorial for COCI '20 Contest 1 #5 Tenis


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
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 \mathcal O(n) pairs of the latter type, and thus it is enough to check, for each position from 1 to n, 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 001, and the player whose best courts (with an equal rank) are the first and the second court would go to the basket 110.

We look for a solution by fixing one player (let's say his best position is p) 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 p. 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 1 in the bitmask. If the bitmask has two or three 1's (equal court winners), we compare positions of a fixed player (the loser) on those courts.


Comments

There are no comments at the moment.