Editorial for Tall
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Subtask 1
For this subtask, we can just brute force all possible values of since any value of above would have bits above set. This would cause the answer to always be .
Time Complexity: or similar
Subtask 2
This subtask is for any solutions that have the same observation as subtask 3 but are otherwise too slow.
Time Complexity: or similar
Subtask 3
Observe that after applying over all , at least one element must be zero so that our MEX is non-zero. Thus, for some so there are only possible values that can be. The MEX of a sequence can be computed in linear time, which is sufficient to pass this subtask.
Time Complexity: or
Full Solution
First, remove any duplicates in the sequence so all elements are unique.
Consider some bit and the least significant bits of the values in the sequence. Divide the sequence by whether each value has the bit corresponding to set, giving us two sets of values. Notice that depending on whether bit is set in or not, one of these will only contain values in the range and the other will only contain values in the range . Call these the lower and upper sets respectively.
Observe that if the lower set has values, then the answer is at least no matter what the lower bits of are, so we can just compute the answer for the bit using the upper set only, yielding us the lower bits of . On the other hand, if the lower set does not have values, then the MEX can be at most so the values of the upper set do not matter since they are all at least . Then, we can do the same as the previous case, except using the lower set instead.
In the worst case, we just need to compute the answer for bit using the two sets of numbers individually, and can then use those answers to compute the final answer in time. Starting this search from the most significant bit yields us a divide and conquer solution.
Time Complexity:
Comments