Let the liar segment be [L,R]. Person i is a liar exactly when iβ[L,R], while person i's claim is true exactly when [liβ,riβ] intersects [L,R]. These two Boolean values must be different.
If the set for M(L) is empty, use 0. If the set for G(L) is empty, use N+1.
An interval [L,R] is valid if and only if
Lβ€A,max(B,L,M(L))β€R<G(L).
The first inequality eliminates every case of the form diβ<L. The bound Rβ₯B eliminates every case of the form R<ciβ. The bound Rβ₯M(L) eliminates every case of the form aiβ<Lβ€R<biβ. Finally, R<G(L) eliminates every person satisfying Lβ€aiβ and biββ€R. Thus the criterion removes exactly all contradictions listed above.
We now maintain M(L) and G(L) dynamically. For every coordinate x, maintain
Then M(L) is a prefix maximum of hi, and G(L) is a suffix minimum of lo. People with the same aiβ are stored in a multiset. The values A and B are maintained with multisets of diβ and ciβ as well.
Split the coordinates 1,2,β―,N into blocks of size about Nβ. For every candidate L in a block [s,e], precompute
Both XLβ and YLβ are nondecreasing as L increases. Also store all positions satisfying XLβ<YLβ.
Let P be the maximum hi value in all earlier blocks, and let S be the minimum lo value in all later blocks. A candidate L in this block is feasible exactly when
max(B,P,XLβ)<min(S,YLβ).
This is equivalent to the following four conditions.
max(B,P)<S.
XLβ<S.
YLβ>max(B,P).
XLβ<YLβ.
Because XLβ and YLβ are monotone, two binary searches give the range of positions satisfying the middle bounds. We then check whether one of the stored positions with XLβ<YLβ lies in that range. Once such an L is found, set
R=max(B,P,XLβ).
Only candidates with Lβ€A are considered.
One claim update changes only the blocks containing the old and new values of aiβ. Therefore, at most two blocks need to be rebuilt.
The time complexity per update is O(NβlogN), and the memory complexity is O(N).