use input::input_array; use input::input_vec; fn main() { let [n, _m] = input_array::(); let mut a = input_vec::(); for x in &mut a { *x -= 1; } let mut dist = (0..n as isize).collect::>(); for &x in a.iter().rev() { dist.swap(x, x + 1); for i in 0..n - 1 { dist[i + 1] = dist[i + 1].min(dist[i] + 1); } for i in (0..n - 1).rev() { dist[i] = dist[i].min(dist[i + 1] + 1); } } println!( "{}", dist[1..] .iter() .map(|x| x.to_string()) .collect::>() .join(" ") ); } // input {{{ #[allow(dead_code)] mod input { use std::cell::Cell; use std::convert::TryFrom; use std::io::stdin; use std::io::BufRead; use std::io::BufReader; use std::io::Lines; use std::io::Stdin; use std::str::FromStr; use std::sync::Mutex; use std::sync::Once; type Server = Mutex>>; static ONCE: Once = Once::new(); pub struct Lazy(Cell>); unsafe impl Sync for Lazy {} fn line() -> String { static SYNCER: Lazy = Lazy(Cell::new(None)); ONCE.call_once(|| { SYNCER .0 .set(Some(Mutex::new(BufReader::new(stdin()).lines()))); }); unsafe { (*SYNCER.0.as_ptr()) .as_ref() .unwrap() .lock() .unwrap() .next() .unwrap() .unwrap() } } pub trait ForceFromStr: FromStr { fn force_from_str(s: &str) -> Self; } impl ForceFromStr for T where T: FromStr, E: std::fmt::Debug, { fn force_from_str(s: &str) -> Self { s.parse().unwrap() } } pub fn input_array() -> [T; N] where T: std::fmt::Debug, { <[_; N]>::try_from(input_vec()).unwrap() } pub fn input_vec() -> Vec { line() .split_whitespace() .map(T::force_from_str) .collect::>() } pub fn input() -> T { T::force_from_str(&line()) } } // }}}