No.2930 Larger Mex
タグ : / 解いたユーザー数 99
作問者 :
kusirakusira
👑
mymelochan
tnodino
Problem Statement
You are given a sequence of non-negative integers $A=(A_1,A_2,\dots,A_N)$ of length $N$ and a non-negative integer $M$. Solve the following problem for each of $k=1,\dots,N$.
Find the number of contiguous subarrays of $A$ of length $k$ whose $\mathrm{mex}$ is at least $M$.
More precisely, find the number of pairs of positive integers $(l,r)$ that satisfy all of the following.
- $1\leq l\leq r\leq N$
- $r-l+1=k$
- $\mathrm{mex}(A_l,A_{l+1},\dots,A_r)\geq M$
What is $\mathrm{mex}$?
The $\mathrm{mex}$ of a set or sequence is the smallest non-negative integer not contained in it.
For example, $\mathrm{mex}(\{0,1,1,2,4\})=3,\mathrm{mex}(\{1,2,3\})=0$.
Constraints
- $1\leq N\leq 2\times 10^5$
- $0\leq M\leq 2\times 10^5$
- $0\leq A_i\leq 2\times 10^5$
- All inputs are integers.
Input
The input is given from standard input in the following format.
$N$ $M$ $A_1$ $A_2$ $\dots$ $A_N$
Output
Print $N$ lines. The $i$-th line should contain the answer for $k=i$.
Sample
Sample 1
Input
5 1 0 3 1 0 2
Output
2 3 3 2 1
- When $k=1$, the contiguous subarrays of $A$ of length $k$ are $(0),(3),(1),(0),(2)$, and their respective $\mathrm{mex}$ values are $1,0,0,1,0$, so $2$ of them are at least $M$.
- When $k=2$, the contiguous subarrays of $A$ of length $k$ are $(0,3),(3,1),(1,0),(0,2)$, and their respective $\mathrm{mex}$ values are $1,0,2,1$, so $3$ of them are at least $M$.
- When $k=3$, the contiguous subarrays of $A$ of length $k$ are $(0,3,1),(3,1,0),(1,0,2)$, and their respective $\mathrm{mex}$ values are $2,2,3$, so $3$ of them are at least $M$.
- When $k=4$, the contiguous subarrays of $A$ of length $k$ are $(0,3,1,0),(3,1,0,2)$, and their respective $\mathrm{mex}$ values are $2,4$, so $2$ of them are at least $M$.
- When $k=5$, the contiguous subarray of $A$ of length $k$ is $(0,3,1,0,2)$, and its $\mathrm{mex}$ is $4$, so $1$ of them is at least $M$.
Sample 2
Input
4 0 1 2 3 4
Output
4 3 2 1
Sample 3
Input
20 3 0 2 1 1 1 5 7 0 2 1 4 1 4 8 0 3 0 0 4 2
Output
0 0 2 3 5 6 9 9 10 10 10 9 8 7 6 5 4 3 2 1
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。