library_checker/tree/cartesian_tree.rs
1#[doc(no_inline)]
2pub use competitive::algorithm::CartesianTree;
3use competitive::prelude::*;
4
5#[verify::library_checker("cartesian_tree")]
6pub fn cartesian_tree(reader: impl Read, mut writer: impl Write) {
7 let s = read_all_unchecked(reader);
8 let mut scanner = Scanner::new(&s);
9 scan!(scanner, n, a: [i32; n]);
10 let ct = CartesianTree::new(&a);
11 iter_print!(writer, @it ct.parents.iter().map(|&p| if p == !0 { ct.root } else { p }) );
12}