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: (N/2)2 pairs

Set all ai=1.

Then, set aN/2=1010.

Any pair (l,r) satisfying 1lN/2rN is valid.

Thus, there are approximately (N/2)2 such pairs.

Method 2: 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 LlrR are valid. The intended solution uses the following method:

1) If L > R, return.

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

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

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

  • All pairs (l,r) satisfying LlrM1 or M+1lrR are valid now.

4) Set aM to (aL+aL+1++aM1)+(aM+1+aM+2++aR)+1

  • aM is the minimum amount required to make all pairs (l,r) satisfying LlMrR valid.

Now, all pairs satisfying LlrR are valid!

We can call this recursive function on (1, N) to receive full points. The maximum value that this construction uses when N=2×105 is 7380642475, around 7×109. This fits comfortably under the 1010 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.