#![allow(non_snake_case, unused_must_use, unused_imports)] use std::io::{self, prelude::*}; fn main() { let (stdin, stdout) = (io::read_to_string(io::stdin()).unwrap(), io::stdout()); let (mut stdin, mut buffer) = (stdin.split_whitespace(), io::BufWriter::new(stdout.lock())); macro_rules! input { ($t: tt, $n: expr) => { (0..$n).map(|_| input!($t)).collect::>() }; (Chars) => { input!(String).chars().collect::>() }; (Usize1) => { stdin.next().unwrap().parse::().unwrap() - 1 }; ($t: ty) => { stdin.next().unwrap().parse::<$t>().unwrap() }; } let N = input!(usize); let M = input!(usize); if M == 0 { for i in (1..=N).rev() { writeln!(buffer, "{}", i); } return; } let A = input!(usize, N); let mut positions: segtree::SegmentTree> = segtree::SegmentTree::from(&vec![usize::MAX; M]); let mut cs = vec![0; N + 1]; for i in (0..N).rev() { let a = A[i]; if a < M { positions.insert(a, i); } let r = positions.prod(0..M); if r != usize::MAX { cs[r - i] += 1; cs[N - i] -= 1; } } let mut ans = vec![cs[0]]; for i in 1..N { ans.push(ans[i - 1] + cs[i]); } writeln!( buffer, "{}", ans.iter() .map(|x| x.to_string()) .collect::>() .join("\n") ); } #[rustfmt::skip] pub mod segtree {use crate::algebra::Monoid;pub struct SegmentTree { size: usize, tree: Vec,}impl SegmentTree { pub fn new(size: usize) -> Self { Self { size, tree: vec![M::E; size << 1], } } pub fn from(array: &[M::S]) -> Self { let size = array.len(); let tree = { let mut tree = vec![M::E; size]; tree.append(&mut array.to_vec()); for i in (1..size).rev() { tree[i] = M::op(&tree[i << 1], &tree[i << 1 | 1]); } tree }; return Self { size, tree }; } pub fn insert(&mut self, mut i: usize, s: M::S) { assert!(i < self.size); i += self.size; self.tree[i] = s; while i > 1 { i >>= 1; self.tree[i] = M::op(&self.tree[i << 1], &self.tree[i << 1 | 1]); } } pub fn get(&self, i: usize) -> M::S { assert!(i < self.size); self.tree[i + self.size].clone() } pub fn prod>(&self, range: R) -> M::S { let left = match range.start_bound() { std::ops::Bound::Included(&l) => l, std::ops::Bound::Excluded(&l) => l + 1, std::ops::Bound::Unbounded => 0, }; let right = match range.end_bound() { std::ops::Bound::Included(&r) => r + 1, std::ops::Bound::Excluded(&r) => r, std::ops::Bound::Unbounded => self.size, }; return self._prod(left, right); } fn _prod(&self, mut left: usize, mut right: usize) -> M::S { left += self.size; right += self.size; let (mut sl, mut sr) = (M::E, M::E); while left < right { if left & 1 == 1 { sl = M::op(&sl, &self.tree[left]); left += 1; } if right & 1 == 1 { right ^= 1; sr = M::op(&self.tree[right], &sr); } left >>= 1; right >>= 1; } return M::op(&sl, &sr); }}impl std::ops::Index for SegmentTree { type Output = M::S; fn index(&self, index: usize) -> &Self::Output { &self.tree[index + self.size] }}impl, S: std::fmt::Display> std::fmt::Display for SegmentTree { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!( f, "{}", (0..self.size) .map(|i| self.get(i)) .collect::>() .iter() .map(|x| x.to_string()) .collect::>() .join(" ") ) }}} #[rustfmt::skip] pub mod algebra {pub trait SemiGroup { type S; fn op(lhs: &Self::S, rhs: &Self::S) -> Self::S;}pub trait Band { type S; fn op(lhs: &Self::S, rhs: &Self::S) -> Self::S;}pub trait Monoid { type S: Clone + PartialEq + Eq; fn op(lhs: &Self::S, rhs: &Self::S) -> Self::S; const E: Self::S;}pub struct Min { _marker: std::marker::PhantomData,}pub struct Max { _marker: std::marker::PhantomData,}pub struct Add { _marker: std::marker::PhantomData,}pub struct Mul { _marker: std::marker::PhantomData,}pub struct BitAnd { _marker: std::marker::PhantomData,}pub struct BitOr { _marker: std::marker::PhantomData,}pub struct BitXor { _marker: std::marker::PhantomData,}macro_rules! impl_to_integers { ($($t: ty), *) => { $( impl SemiGroup for Min<$t> { type S = $t; fn op(lhs: &$t, rhs: &$t) -> $t { std::cmp::min(*lhs, *rhs) } } impl SemiGroup for Max<$t> { type S = $t; fn op(lhs: &$t, rhs: &$t) -> $t { std::cmp::max(*lhs, *rhs) } } impl SemiGroup for Add<$t> { type S = $t; fn op(lhs: &$t, rhs: &$t) -> $t { lhs + rhs } } impl SemiGroup for Mul<$t> { type S = $t; fn op(lhs: &$t, rhs: &$t) -> $t { lhs * rhs } } impl SemiGroup for BitAnd<$t> { type S = $t; fn op(lhs: &$t, rhs: &$t) -> $t { lhs & rhs } } impl SemiGroup for BitOr<$t> { type S = $t; fn op(lhs: &$t, rhs: &$t) -> $t { lhs | rhs } } impl SemiGroup for BitXor<$t> { type S = $t; fn op(lhs: &$t, rhs: &$t) -> $t { lhs ^ rhs } } impl Band for Min<$t> { type S = $t; fn op(lhs: &$t, rhs: &$t) -> $t { std::cmp::min(*lhs, *rhs) } } impl Band for Max<$t> { type S = $t; fn op(lhs: &$t, rhs: &$t) -> $t { std::cmp::max(*lhs, *rhs) } } impl Band for BitAnd<$t> { type S = $t; fn op(lhs: &$t, rhs: &$t) -> $t { lhs & rhs } } impl Band for BitOr<$t> { type S = $t; fn op(lhs: &$t, rhs: &$t) -> $t { lhs | rhs } } impl Monoid for Min<$t> { type S = $t; fn op(lhs: &$t, rhs: &$t) -> $t { std::cmp::min(*lhs, *rhs) } const E: $t = <$t>::MAX; } impl Monoid for Max<$t> { type S = $t; fn op(lhs: &$t, rhs: &$t) -> $t { std::cmp::max(*lhs, *rhs) } const E: $t = <$t>::MIN; } impl Monoid for Add<$t> { type S = $t; fn op(lhs: &$t, rhs: &$t) -> $t { lhs + rhs } const E: $t = 0; } impl Monoid for Mul<$t> { type S = $t; fn op(lhs: &$t, rhs: &$t) -> $t { lhs * rhs } const E: $t = 1; } impl Monoid for BitAnd<$t> { type S = $t; fn op(lhs: &$t, rhs: &$t) -> $t { lhs & rhs } const E: $t = <$t>::MAX; } impl Monoid for BitOr<$t> { type S = $t; fn op(lhs: &$t, rhs: &$t) -> $t { lhs | rhs } const E: $t = 0; } impl Monoid for BitXor<$t> { type S = $t; fn op(lhs: &$t, rhs: &$t) -> $t { lhs ^ rhs } const E: $t = 0; } )* };}impl_to_integers!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);}