Hints: Sakurako's Test
There is a very standard trick of converting Median based problems to Sum based problems. I learnt it from a recent Codeforces Problem : Med-imize
Notice that
From this number line, how do you locate the median?
Let’s define
The median would be the first position where the prefix sum of this number line is
Now, I’ll show you an alternate way to compute the median.
If you define
That’s a trick question. true
and all other values would be false
.
So, let’s modify it a bit. Define
Yes, because if the actual median is false
and all
Hence, we can binary search on this
So, even though you could traverse from left to right and compute the median at the first point where the prefix sum becomes
So now, suppose you are given an
true
only if we can stuff atleast
Recall Euclid’s divison lemma
Therefore, the leftmost position that we could stuff
For each false
, else it is true.
Notice that on the number lines, the modulo would look like
If
What is the total number of occurrences of such 0s across all