5003.MEX

时间限制:3s 内存限制:512MB

小 $\mathcal{L}$ 给出一个长度为 $n$ 的序列 $a$,序列中的每一个元素都在 $[0,m)$ 范围内,现在对于每一个 $i\in[p,q]$ 求出有多少个区间 $[l,r]$ 中元素构成的集合的 $\operatorname{MEX}$ 为 $i$。(一个集合的 $\operatorname{MEX}$ 为这个集合中第一个没有出现的自然数,如 $\operatorname{MEX}\begin{Bmatrix}0,1,2\end{Bmatrix}=3$,$\operatorname{MEX}\begin{Bmatrix}1,2,3\end{Bmatrix}=0$)

输入格式(从终端/标准输入读取)

第一行两个整数 $n,m$,表示序列长度和数集大小。

第二行 $n$ 个整数,表示序列 $a$,且保证序列 $a$ 中元素在 $[0,m)$ 范围内。

第三行两个整数 $p,q$,表示小 $\mathcal{L}$ 要查询的范围。

输出格式(输出至终端/标准输出)

一行 $q-p+1$ 个整数,其中第 $i$ 个表示有多少个区间 $[l,r]$ 中的元素构成的集合的 $\operatorname{MEX}$ 为 $p+i-1$。

输入样例1

复制
5 3
0 1 2 1 0
0 3
 · \n
 · · · · \n
 · \n

输出样例1

复制
6 2 2 5
 · · · \n

输入样例2

复制
8 4
0 1 2 3 0 1 2 3
0 4
 · \n
 · · · · · · · \n
 · \n

输出样例2

复制
12 4 3 2 15
  · · · ·  \n

说明

样例 1 解释:

其中 $\operatorname{MEX}$ 为 $0$ 的区间有: $[2,2],[2,3],[2,4],[3,3],[3,4],[4,4]$,共 $6$ 个;
其中 $\operatorname{MEX}$ 为 $1$ 的区间有: $[1,1],[5,5]$,共 $2$ 个;
其中 $\operatorname{MEX}$ 为 $2$ 的区间有: $[1,2],[4,5]$,共 $2$ 个;
其中 $\operatorname{MEX}$ 为 $3$ 的区间有: $[1,3],[1,4],[1,5],[2,5],[3,5]$,共 $5$ 个。

样例 2 解释:

其中 $\operatorname{MEX}$ 为 $0$ 的区间有: $[2,2],[2,3],[2,4],[3,3],[3,4],[4,4],[6,6],[6,7],[6,8],[7,7],[7,8],[8,8]$,共 $12$ 个;
其中 $\operatorname{MEX}$ 为 $1$ 的区间有: $[1,1],[3,5],[4,5],[5,5]$,共 $4$ 个;
其中 $\operatorname{MEX}$ 为 $2$ 的区间有: $[1,2],[4,6],[5,6]$,共 $3$ 个;
其中 $\operatorname{MEX}$ 为 $3$ 的区间有: $[1,3],[5,7]$,共 $2$ 个;
其中 $\operatorname{MEX}$ 为 $4$ 的区间有: $[1,4],[1,5],[1,6],[1,7],[1,8],[2,5],[2,6],[2,7],[2,8],[3,6],[3,7],[3,8],[4,7],[4,8],[5,8]$,共 $15$ 个。

对于 $100\%$​ 的数据 $0\leq p\leq q\leq m\leq n\leq 10^6$。

提交题解

Please login first.

© 2025 FAQs