Editorial for UTS Open '24 P4 - Political Espionage


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.

Author: Sucram314

The subtasks are meant to reward all suboptimal solutions and are not tied to any specific methods. Here are some common constructions:

Method 1: \sim\left(N/2\right)^2 pairs

Set all a_i = 1.

Then, set a_{\left\lfloor N/2 \right\rfloor} = 10^{10}.

Any pair (l,r) satisfying 1 \le l \le \left\lfloor N/2 \right\rfloor \le r \le N is valid.

Thus, there are approximately \left(N/2\right)^2 such pairs.

Method 2: \to N(N+1)/2 pairs

Recurse Method 1 on both halves of the current range. The values you set for the numbers in the middle should decrease a sufficient amount (e.g. various functions work, but floor dividing by four is a simple example).

This method approaches N(N+1)/2 pairs, but may run into issues for larger N. Fine tuning the decreasing function may result in full points.

Intended Solution: N(N+1)/2 pairs

Instead of building the array top down, we can build it bottom up. Define a recursive function that constructs a range of the array, (L, R), ensuring that all pairs (l,r) satisfying L \le l \le r \le R are valid. The intended solution uses the following method:

1) If L > R, return.

2) If L == R, set a_L = 1

  • (L,L) is a valid pair now. \checkmark

3) Otherwise, let M = (L + R) / 2. Recurse on (L, M-1) and (M+1, R).

  • All pairs (l,r) satisfying L \le l \le r \le M-1 or M+1 \le l \le r \le R are valid now. \checkmark

4) Set a_M to (a_L + a_{L+1} + \dots + a_{M-1}) + (a_{M+1} + a_{M+2} + \dots + a_R) + 1

  • a_M is the minimum amount required to make all pairs (l,r) satisfying L \le l \le M \le r \le R valid. \checkmark

Now, all pairs satisfying L \le l \le r \le R are valid! \checkmark

We can call this recursive function on (1, N) to receive full points. The maximum value that this construction uses when N = 2 \times 10^5 is 7380642475, around 7 \times 10^9. This fits comfortably under the 10^{10} limit.

Bonus

Python golf solution (87 bytes): https://dmoj.ca/src/6848763 (Credits to Riolku for the bulk of the logic + Josh for optimizing it with walrus operator)


Comments

There are no comments at the moment.