跳到正文

题解

题解:AT_abc478_c [ABC478C] Sort Subarray

wyyinput约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年10月4日
收录
2026年10月5日
更新
2026年11月9日
篇幅
约 1 分钟
获赞
1

版本

  1. v1当前

A simple problem.

Since NN and KK are below 2×1052\times 10^5, we may need an O(N)O(N) or O(Nlog⁡N)O(N\log N) solution.

Consider sorting the interval [L,R][L,R], we need to make sure that:

  1. For all i(2≤i<L)i(2\le i < L), Ai≥Ai−1A_i \ge A_{i-1}.
  2. For all i(R<i<N)i(R < i < N), Ai≤Ai+1A_i \le A_{i+1}.
  3. max⁡i=LRAi\max \limits _{i=L} ^{R} A_i mustn’t be bigger than AR+1A_{R+1}. (You may consider AN+1A_{N+1} infinity.)
  4. min⁡i=LRAi\min \limits _{i=L} ^{R} A_i mustn’t be smaller than AL−1A_{L-1}.

By spending O(N)O(N) time initializing 1 and 2, and using segment tree or ST table, we can solve this problem in O(Nlog⁡N)O(N \log N) time, O(Nlog⁡N)O(N\log N) space. This problem can also be solved in O(N)O(N) time.

原文