Problem: 2049C - MEX Cycle
Language: Rust 2021

Previous submission (verdict: Wrong answer on test 2):
// https://codeforces.com/contest/2049/problem/C



#[allow(unused_imports)]

use alg::io::read;



fn main() {

    for _ in 0..read() {

        solve();

    }

}



fn solve() {

    input! {

        n: usize,

        x: usize,

        y: usize,

    }

    let a = ring(n, x, y);

    for i in 0..n {

        print!("{} ", a[i]);

    }

    println!();

}



fn ring(n: usize, x: usize, y: usize) -> Vec<usize> {

    let x = x - 1;

    let y = y - 1;

    if n == 4 && y - x == 2 {

        return vec![1, 2, 1, 0];

    }

    assert!(x < y);

    let mut a = vec![3; n];

    let l1 = y - x + 1;

    let l2 = x + n - y + 1;

    a[(x + n - 1) % n] = l2 % 2 + 1;

    a[x] = 0;

    a[x + 1] = l1 % 2 + 1;

    for i in (x + 2)..y {

        a[i] = (a[i - 1] + 1) % 2;

    }

    a[y] = 1;

    for i in (y + 1)..(n + x - 1) {

        a[i % n] = 1 - a[(i - 1) % n];

    }

    a

}



#[cfg(test)]

mod tests {

    use super::*;



    #[test]

    fn test() {

        ring(4, 2, 4);

    }

}



mod alg {

pub mod io {

#[macro_export]

macro_rules! input {

    (mut $var:ident: $kind:tt, $($rest:tt)*) => {

        let mut $var = $crate::_input_kind!($kind);

        input!($($rest)*)

    };

    ($var:ident: $kind:tt, $($rest:tt)*) => {

        let $var = $crate::_input_kind!($kind);

        input!($($rest)*)

    };

    (mut $var:ident: $kind:tt) => { let mut $var = $crate::_input_kind!($kind); };

    ($var:ident: $kind:tt) => { let $var = $crate::_input_kind!($kind); };

    () => {};

}



#[doc(hidden)]

#[macro_export]

macro_rules! _input_kind {

    ([$t:tt; $n:expr]) => {

        (0..$n).map(|_| $crate::_input_kind!($t)).collect::<Vec<_>>()

    };

    ([$t:tt]) => {{

        let n = $crate::_input_kind!(usize);

        (0..n).map(|_| $crate::_input_kind!($t)).collect::<Vec<_>>()

    }};

    (($a:tt, $b:tt)) => {{

        let a = $crate::_input_kind!($a);

        let b = $crate::_input_kind!($b);

        (a, b)

    }};

    (bytes) => {

        $crate::_input_kind!(String).into_bytes()

    };

    (usize1) => {

        $crate::_input_kind!(usize) - 1

    };

    ($t:ty) => {

        $crate::alg::io::read::<$t>()

    };

}



pub fn read<T>() -> T

where

    T: std::str::FromStr,

    T::Err: std::fmt::Debug,

{

    use std::cell::RefCell;

    use std::io::{stdin, BufRead, StdinLock};

    thread_local! {

        pub static STDIN: RefCell<StdinLock<'static>> = RefCell::new(stdin().lock());

    }

    STDIN.with(|r| {

        let mut r = r.borrow_mut();

        let mut s = vec![];

        loop {

            let buf = r.fill_buf().unwrap();

            if buf.is_empty() {

                break;

            }

            if let Some(i) = buf.iter().position(u8::is_ascii_whitespace) {

                s.extend_from_slice(&buf[..i]);

                r.consume(i + 1);

                if !s.is_empty() {

                    break;

                }

            } else {

                s.extend_from_slice(buf);

                let n = buf.len();

                r.consume(n);

            }

        }

        std::str::from_utf8(&s).unwrap().parse().unwrap()

    })

}



#[macro_export]

macro_rules! println {

        ($($arg:tt)*) => {

            $crate::alg::io::_with_stdout(|w| {

                use std::io::Write;

                std::writeln!(w, $($arg)*).unwrap()

            })

        };

    }



#[macro_export]

macro_rules! print {

        ($($arg:tt)*) => {

            $crate::alg::io::_with_stdout(|w| {

                use std::io::Write;

                std::write!(w, $($arg)*).unwrap()

            })

        };

    }



#[doc(hidden)]

pub fn _with_stdout<F>(f: F)

where

    F: FnOnce(&mut std::io::BufWriter<std::io::StdoutLock>),

{

    use std::cell::RefCell;

    use std::io::{stdout, BufWriter, StdoutLock};

    thread_local! {

        pub static STDOUT: RefCell<BufWriter<StdoutLock<'static>>> =

            RefCell::new(BufWriter::new(stdout().lock()));

    }

    STDOUT.with(|w| f(&mut w.borrow_mut()))

}

}

}



Submission (verdict: Wrong answer on test 2):
// https://codeforces.com/contest/2049/problem/C



#[allow(unused_imports)]

use alg::io::read;



fn main() {

    for _ in 0..read() {

        solve();

    }

}



fn solve() {

    input! {

        n: usize,

        x: usize,

        y: usize,

    }

    let a = ring(n, x, y);

    for i in 0..n {

        print!("{} ", a[i]);

    }

    println!();

}



fn ring(n: usize, x: usize, y: usize) -> Vec<usize> {

    let x = x - 1;

    let y = y - 1;

    if n == 4 && y - x == 2 {

        return vec![1, 2, 1, 0];

    }

    assert!(x < y);

    let mut a = vec![3; n];

    if x + 1 == y || (y + 1) % n == x {

        a[0] = n % 2 + 1;

        for i in 1..n {

            a[i] = (a[i - 1] + 1) % 2;

        }

        return a;

    }

    let l1 = y - x + 1;

    let l2 = x + n - y + 1;

    a[(x + n - 1) % n] = l2 % 2 + 1;

    a[x] = 0;

    a[x + 1] = l1 % 2 + 1;

    for i in (x + 2)..y {

        a[i] = (a[i - 1] + 1) % 2;

    }

    a[y] = 1;

    for i in (y + 1)..(n + x - 1) {

        a[i % n] = (a[(i - 1) % n] + 1) % 2;

    }

    a

}



#[cfg(test)]

mod tests {

    use super::*;



    #[test]

    fn test1() {

        assert_eq!(ring(4, 2, 4), vec![1, 2, 1, 0]);

        assert_eq!(ring(4, 1, 4), vec![1, 0, 1, 0]);

    }

}



mod alg {

pub mod io {

#[macro_export]

macro_rules! input {

    (mut $var:ident: $kind:tt, $($rest:tt)*) => {

        let mut $var = $crate::_input_kind!($kind);

        input!($($rest)*)

    };

    ($var:ident: $kind:tt, $($rest:tt)*) => {

        let $var = $crate::_input_kind!($kind);

        input!($($rest)*)

    };

    (mut $var:ident: $kind:tt) => { let mut $var = $crate::_input_kind!($kind); };

    ($var:ident: $kind:tt) => { let $var = $crate::_input_kind!($kind); };

    () => {};

}



#[doc(hidden)]

#[macro_export]

macro_rules! _input_kind {

    ([$t:tt; $n:expr]) => {

        (0..$n).map(|_| $crate::_input_kind!($t)).collect::<Vec<_>>()

    };

    ([$t:tt]) => {{

        let n = $crate::_input_kind!(usize);

        (0..n).map(|_| $crate::_input_kind!($t)).collect::<Vec<_>>()

    }};

    (($a:tt, $b:tt)) => {{

        let a = $crate::_input_kind!($a);

        let b = $crate::_input_kind!($b);

        (a, b)

    }};

    (bytes) => {

        $crate::_input_kind!(String).into_bytes()

    };

    (usize1) => {

        $crate::_input_kind!(usize) - 1

    };

    ($t:ty) => {

        $crate::alg::io::read::<$t>()

    };

}



pub fn read<T>() -> T

where

    T: std::str::FromStr,

    T::Err: std::fmt::Debug,

{

    use std::cell::RefCell;

    use std::io::{stdin, BufRead, StdinLock};

    thread_local! {

        pub static STDIN: RefCell<StdinLock<'static>> = RefCell::new(stdin().lock());

    }

    STDIN.with(|r| {

        let mut r = r.borrow_mut();

        let mut s = vec![];

        loop {

            let buf = r.fill_buf().unwrap();

            if buf.is_empty() {

                break;

            }

            if let Some(i) = buf.iter().position(u8::is_ascii_whitespace) {

                s.extend_from_slice(&buf[..i]);

                r.consume(i + 1);

                if !s.is_empty() {

                    break;

                }

            } else {

                s.extend_from_slice(buf);

                let n = buf.len();

                r.consume(n);

            }

        }

        std::str::from_utf8(&s).unwrap().parse().unwrap()

    })

}



#[macro_export]

macro_rules! println {

        ($($arg:tt)*) => {

            $crate::alg::io::_with_stdout(|w| {

                use std::io::Write;

                std::writeln!(w, $($arg)*).unwrap()

            })

        };

    }



#[macro_export]

macro_rules! print {

        ($($arg:tt)*) => {

            $crate::alg::io::_with_stdout(|w| {

                use std::io::Write;

                std::write!(w, $($arg)*).unwrap()

            })

        };

    }



#[doc(hidden)]

pub fn _with_stdout<F>(f: F)

where

    F: FnOnce(&mut std::io::BufWriter<std::io::StdoutLock>),

{

    use std::cell::RefCell;

    use std::io::{stdout, BufWriter, StdoutLock};

    thread_local! {

        pub static STDOUT: RefCell<BufWriter<StdoutLock<'static>>> =

            RefCell::new(BufWriter::new(stdout().lock()));

    }

    STDOUT.with(|w| f(&mut w.borrow_mut()))

}

}

}