DOJ logoDOJ
Problems
Recently added problemsSaved problems
CategoriesDLCContestsGroupsTeamsBoard
Ranking
Solved Problem RankingStreak rankingDOJ Power ranking
Status
Call for TasksLoginRegister
DOJ logoDOJ

Community online judge with OI-style subtask scoring, Elo ratings, and Discord-backed certification.

Problems
ProblemsCategories
Community
ContestsRankingBoardNoticesHost an external contestGuide
Account
LoginRegisterJudge Status
Policy
Terms of ServiceDLC RulesPrivacyAPI documentationLanguage runtimesContest rank rewardsRating and performance
© 2026 DOJ
All rights reserved
Editorial

Cheaters and Queries

Back to problem

Editorial

Let the liar segment be [L,R][L,R][L,R]. Person iii is a liar exactly when i∈[L,R]i \in [L,R]i∈[L,R], while person iii's claim is true exactly when [li,ri][l_i,r_i][li​,ri​] intersects [L,R][L,R][L,R]. These two Boolean values must be different.

For every person, define

ai=min⁡(i,ri),bi=max⁡(i,li),ci=min⁡(i,li),di=max⁡(i,ri).a_i=\min(i,r_i),\qquad b_i=\max(i,l_i),\qquad c_i=\min(i,l_i),\qquad d_i=\max(i,r_i).ai​=min(i,r

Person iii is inside the liar segment and has a true claim exactly when L≤aiL \leq a_iL≤ai​ and bi≤Rb_i \leq Rbi​.

Person iii is outside the liar segment and also has a false claim in one of the following three forms.

  • R<ciR<c_iR<ci​.
  • di<Ld_i<Ldi​<L.
  • . The last form occurs when the liar segment lies strictly between person and their claim interval.

Define

A=min⁡idi,B=max⁡ici,A=\min_i d_i,\qquad B=\max_i c_i,A=imin​di​,B= M(L)=max⁡ai<Lbi,G(L)=min⁡ai≥Lbi.M(L)=\max_{a_i<L} b_i,\qquad G(L)=\min_{a_i\geq L} b_i.M(L)=ai​<Lmax​

If the set for M(L)M(L)M(L) is empty, use 000. If the set for G(L)G(L)G(L) is empty, use N+1N+1N+1.

An interval [L,R][L,R][L,R] is valid if and only if

L≤A,max⁡(B,L,M(L))≤R<G(L).L\leq A,\qquad \max(B,L,M(L))\leq R<G(L).L≤A,max(B,L,M(L))≤R<G(L).

The first inequality eliminates every case of the form di<Ld_i<Ldi​<L. The bound R≥BR\geq BR≥B eliminates every case of the form R<ciR<c_iR<. 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 M(L)M(L)M(L) and G(L)G(L)G(L) dynamically. For every coordinate xxx, maintain

hix=max⁡ai=xbi,lox=min⁡ai=xbi.\mathrm{hi}_x=\max_{a_i=x} b_i,\qquad \mathrm{lo}_x=\min_{a_i=x} b_i.hix​=a

Then M(L)M(L)M(L) is a prefix maximum of hi\mathrm{hi}hi, and G(L)G(L)G(L) is a suffix minimum of lo\mathrm{lo}lo. People with the same aia_ia are stored in a multiset. The values and are maintained with multisets of and as well.

Split the coordinates 1,2,⋯ ,N1,2,\cdots,N1,2,⋯,N into blocks of size about N\sqrt NN​. For every candidate in a block , precompute

XL=max⁡(L,max⁡s≤x<Lhix),YL=min⁡L≤x≤elox.X_L=\max\left(L,\max_{s\leq x<L}\mathrm{hi}_x\right),\qquad Y_L=\min_{L\leq x\leq e}\mathrm{lo}_x.XL​=max(L,

Both XLX_LXL​ and YLY_LYL​ are nondecreasing as LLL increases. Also store all positions satisfying XL<YL.

Let PPP be the maximum hi\mathrm{hi}hi value in all earlier blocks, and let SSS be the minimum lo\mathrm{lo}lo value in all later blocks. A candidate LLL in this block is feasible exactly when

max⁡(B,P,XL)<min⁡(S,YL).\max(B,P,X_L)<\min(S,Y_L).max(B,P,XL​)<min(S,YL​

This is equivalent to the following four conditions.

  • max⁡(B,P)<S\max(B,P)<Smax(B,P)<S.
  • XL<SX_L<SXL​<S.
  • YL>max⁡.

Because XLX_LXL​ and YLY_LYL​ 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<YLX_L<Y_LX lies in that range. Once such an is found, set

R=max⁡(B,P,XL).R=\max(B,P,X_L).R=max(B,P,XL​).

Only candidates with L≤AL\leq AL≤A are considered.

One claim update changes only the blocks containing the old and new values of aia_iai​. Therefore, at most two blocks need to be rebuilt.

The time complexity per update is O(Nlog⁡N)O(\sqrt N\log N)O(N​logN), and the memory complexity is O(N)O(N)O(N).

Solution written by GPT5.6

i​
)
,
bi​
=
max(i,li​),ci​=
min(i,li​),di​=
max(i,ri​).
≤
R
ai<L≤R<bia_i<L \leq R<b_i
ai​<L≤R<bi​
iii
imax​
ci​
,
bi​
,
G
(
L
)
=
ai​≥Lmin​bi​.
ci​
R≥M(L)R\geq M(L)R≥M(L)
ai<L≤R<bia_i<L \leq R<b_iai​<L≤R<bi​
R<G(L)R<G(L)R<G(L)
L≤aiL\leq a_iL≤ai​
bi≤Rb_i\leq Rbi​≤R
i
​
=
x
max
​
bi​
,
lox​
=
ai​=xmin​bi​.
i​
AAA
BBB
did_idi​
cic_ici​
LL
L
[s,e][s,e][s,e]
s≤x<L
max
​
hix​
)
,
YL​
=
L≤x≤emin​lox​.
X_L<Y_L
XL​<YL​
)
.
(B,P)Y_L>\max(B,P)
YL​>max(B,P)
  • XL<YLX_L<Y_LXL​<YL​.
  • L​
    <
    YL​
    LLL