跳到正文

题解

题解:AT_arc232_a [ARC232A] Two in the Range

Rainbow_qwq约 2 分钟
原文
文章信息与版本

文章信息

发布
2026年10月13日
收录
2026年11月1日
更新
2026年11月21日
篇幅
约 2 分钟
获赞
12

版本

  1. v1当前

First, delete all intervals that contains some other intervals. If Li≤Lj≤Rj≤RiL_i\le L_j\le R_j\le R_i, mark all positions in [Li,Lj),(Rj,Ri][L_i,L_j),(R_j,R_i] as 00, and delete [Li,Ri][L_i,R_i].

After this, let the remaining intervals be sorted as [L1,R1],…,[Lk,Rk][L_1,R_1],\dots,[L_k,R_k]. Since no interval contains another one, we have L1<L2<⋯<LkL_1<L_2<\dots<L_k and R1<R2<⋯<RkR_1<R_2<\dots<R_k.

For every position pp not marked as 00, the intervals containing pp form a consecutive range, say u,u+1,…,vu,u+1,\dots,v.

Construct a flow graph with vertices 1,2,…,k+11,2,\dots,k+1. For each such position, add an edge (u,v+1)(u,v+1) with capacity 11. Choosing this edge is equivalent to setting xp=1x_p=1. For every ii, the edges crossing the cut between ii and i+1i+1 are exactly the positions contained in [Li,Ri][L_i,R_i].

All intervals have sum 22 iff there is a flow of value 22 from 11 to k+1k+1. So the answer is Yes iff the maximum flow is at least 22.

Time complexity: O(N+M)O(N+M).

原文