QOJ.ac

QOJ

Time Limit: 10 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#964. Excluded Min

Statistics

Ferume は私に、$O(n\sqrt{n} \log n)$ より速く解けるかと尋ねました。そして、私は解くことができました!この問題を作成し、退屈な解法で終わらせなかった彼に感謝します。

$S$ を非負整数を含む多重集合とします。$S$ に対して以下の操作を任意の回数(0回でもよい)行うことができます:$S$ 内に $x$ が少なくとも2つ存在するように $x$ を選び、そのうちの1つを削除し、代わりに $(x - 1)$ または $(x + 1)$ を1つ挿入する(ただし、$(x - 1)$ を挿入できるのはそれが非負の場合のみ)。$F(S)$ を、これらの操作によって達成可能な最大の mex とします。ここで $\text{mex}(S)$ とは、$S$ に含まれない最小の非負整数を指します。

長さ $n$ の配列 $a$ と $q$ 個のクエリ $[l, r]$ が与えられます。各クエリについて、$F(\{a_l, a_{l+1}, \dots, a_r\})$ を求めてください。

入力

1行目に2つの整数 $n, q$ ($1 \le n, q \le 5 \cdot 10^5$) が与えられます。これは配列のサイズとクエリの数です。

2行目に配列 $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 5 \cdot 10^5$) が与えられます。

続く $q$ 行に、各クエリを表す2つの整数 $l_i, r_i$ ($1 \le l_i \le r_i \le n$) が与えられます。

出力

各クエリに対する答えを、入力された順にそれぞれ別の行に出力してください。

入出力例

入力 1

3 3
0 0 2
1 3
2 3
3 3

出力 1

3
1
0

入力 2

3 2
1 2 2
1 2
1 3

出力 2

0
3

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1105EditorialOpen对询问在线的做法incent2026-03-15 11:41:18View
#614Editorial Open集训队作业 解题报告 by 王一策Qingyu2026-01-02 23:10:24 Download
#591Editorial Open集训队作业 解题报告 by 孙梓航Qingyu2026-01-02 22:41:00 Download
#323EditorialOpen题解jiangly2025-12-14 07:05:13View

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.