Let the liar segment be . Person is a liar exactly when , while person 's claim is true exactly when intersects . These two Boolean values must be different.
For every person, define
Person is inside the liar segment and has a true claim exactly when and .
Person is outside the liar segment and also has a false claim in one of the following three forms.
Define
If the set for is empty, use . If the set for is empty, use .
An interval is valid if and only if
The first inequality eliminates every case of the form . The bound eliminates every case of the form . The bound eliminates every case of the form . Finally, eliminates every person satisfying and . Thus the criterion removes exactly all contradictions listed above.
We now maintain and dynamically. For every coordinate , maintain
Then is a prefix maximum of , and is a suffix minimum of . People with the same are stored in a multiset. The values and are maintained with multisets of and as well.
Split the coordinates into blocks of size about . For every candidate in a block , precompute
Both and are nondecreasing as increases. Also store all positions satisfying .
Let be the maximum value in all earlier blocks, and let be the minimum value in all later blocks. A candidate in this block is feasible exactly when
This is equivalent to the following four conditions.
Because and are monotone, two binary searches give the range of positions satisfying the middle bounds. We then check whether one of the stored positions with lies in that range. Once such an is found, set
Only candidates with are considered.
One claim update changes only the blocks containing the old and new values of . Therefore, at most two blocks need to be rebuilt.
The time complexity per update is , and the memory complexity is .
Solution written by GPT5.6