Editorial
First consider only the prefix records . Define by
If is odd for an odd , or if some is outside , the answer is impossible.
For odd , is the median of the first elements. After adding one new element, the old median must remain one of the two middle elements of the new set of size . Hence, for even , the two middle elements are exactly and .
This gives an interval of values allowed for . For , we must have . For even , let and . If , then ; if , then . The case is impossible because the two middle values are distinct.
For odd , let be the two middle values of the previous even-sized prefix. The new median must lie in . If , then ; if , then ; and if , then . Thus is always one integer interval.
Position restrictions alone are not sufficient. Since is an element already present at time , . Also, if the two middle elements of an even prefix are , no value strictly between them may have appeared yet. Therefore, for every , . Collecting these restrictions gives one interval for every value .
Why the prefix conditions are sufficient
The conditions above are also sufficient. Proceed by induction on the prefix length. Suppose an odd prefix has median , and the other middle value required at the next even step is . The deadline condition guarantees that has already appeared, while the release conditions guarantee that no value between and has appeared. Hence is the element immediately below . Adding a new value makes exactly the two middle values. The case is symmetric.
Process the suffix records symmetrically from right to left. According to the parity of the suffix length , define