/** * _ _ __ _ _ _ _ _ _ _ * | | | | / / | | (_) | (_) | | (_) | | * | |__ __ _| |_ ___ ___ / /__ ___ _ __ ___ _ __ ___| |_ _| |_ ___ _____ ______ _ __ _ _ ___| |_ ______ ___ _ __ _ _ __ _ __ ___| |_ ___ * | '_ \ / _` | __/ _ \ / _ \ / / __/ _ \| '_ ` _ \| '_ \ / _ \ __| | __| \ \ / / _ \______| '__| | | / __| __|______/ __| '_ \| | '_ \| '_ \ / _ \ __/ __| * | | | | (_| | || (_) | (_) / / (_| (_) | | | | | | |_) | __/ |_| | |_| |\ V / __/ | | | |_| \__ \ |_ \__ \ | | | | |_) | |_) | __/ |_\__ \ * |_| |_|\__,_|\__\___/ \___/_/ \___\___/|_| |_| |_| .__/ \___|\__|_|\__|_| \_/ \___| |_| \__,_|___/\__| |___/_| |_|_| .__/| .__/ \___|\__|___/ * | | | | | | * |_| |_| |_| * * https://github.com/hatoo/competitive-rust-snippets */ #[allow(unused_imports)] use std::cmp::{max, min, Ordering}; #[allow(unused_imports)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque}; #[allow(unused_imports)] use std::iter::FromIterator; #[allow(unused_imports)] use std::io::{stdin, stdout, BufWriter, Write}; mod util { use std::io::{stdin, stdout, BufWriter, StdoutLock}; use std::str::FromStr; use std::fmt::Debug; #[allow(dead_code)] pub fn line() -> String { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.trim().to_string() } #[allow(dead_code)] pub fn gets() -> Vec where ::Err: Debug, { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.split_whitespace() .map(|t| t.parse().unwrap()) .collect() } #[allow(dead_code)] pub fn with_bufwriter) -> ()>(f: F) { let out = stdout(); let writer = BufWriter::new(out.lock()); f(writer) } } #[allow(unused_macros)] macro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; } #[allow(unused_macros)] macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { println ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } } #[allow(dead_code)] /// Generic Binary Indexed Tree pub struct BIT ()> { buf: Vec, zero: T, f: F, } impl ()> BIT { #[allow(dead_code)] pub fn new(n: usize, zero: &T, f: F) -> BIT { BIT { buf: vec![zero.clone(); n + 1], zero: zero.clone(), f: f, } } #[allow(dead_code)] pub fn sum(&self, i: usize) -> T { let mut i = i; let mut s = self.zero.clone(); while i > 0 { (self.f)(&mut s, &self.buf[i]); i &= i - 1; } s } #[allow(dead_code)] pub fn add(&mut self, i: usize, x: &T) { let mut i = i as i64; while i < self.buf.len() as i64 { let t = &mut self.buf[i as usize]; (self.f)(t, x); i += i & -i; } } } #[allow(dead_code)] fn main() { let (q, k) = get!(usize, usize); let inputs = get!(String; q); let mut cc: Vec = inputs .iter() .filter_map(|s| { let mut split = s.split_whitespace(); if split.next() == Some("1") { split.next().unwrap().parse().ok() } else { None } }) .collect(); cc.sort(); cc.dedup(); let mut buf: Vec = Vec::with_capacity(q); util::with_bufwriter(|mut out| { for line in inputs { let mut split = line.split_whitespace(); if split.next() == Some("1") { let x: u64 = split.next().unwrap().parse().unwrap(); let y = cc.binary_search(&x).unwrap(); let i = match buf.binary_search(&(y as u32)) { Ok(i) => i, Err(i) => i, }; buf.insert(i, y as u32); } else { if let Some(ans) = buf.get(k - 1).cloned() { writeln!(out, "{}", cc[ans as usize]).unwrap(); buf.remove(k - 1); } else { writeln!(out, "-1").unwrap(); } } } }); }