pub use __cargo_equip::prelude::*; use avl::AVL; use proconio::{fastout, input}; #[fastout] fn main() { input! { q: usize, k: usize, } let mut set = AVL::new(true); for _ in 0..q { input! { t: u8, } if t == 1 { input! { v: u64, } set.insert(v); } else { if set.len() < k { println!("-1"); } else { let ans = set.erase_index(k - 1).unwrap(); println!("{}", ans); } } } } // The following code was expanded by `cargo-equip`. /// # Bundled libraries /// /// - `avl 0.1.0 (path+███████████████████████████████████████████████████████████████)` published in **missing** licensed under **missing** as `crate::__cargo_equip::crates::avl` #[cfg_attr(any(), rustfmt::skip)] #[allow(unused)] mod __cargo_equip { pub(crate) mod crates { pub mod avl {use std::cmp::Ordering;use std::fmt::Display;use std::mem::swap;type Tree =Option>>;#[derive(Debug)]struct Node{left:Tree,right:Tree,value:T,len:usize,height:u8,}implNode{fn new(value:T)->Node{Self{left:None,right:None,value,len:1,height:1,}}fn update(&mut self){self.len=len(&self.left)+len(&self.right)+1;self.height=height(&self.left).max(height(&self.right))+1;}fn rotate_right(&mut self){let mut x=self.left.take().unwrap();let b=x.right.take();swap(self,&mut x);x.left=b;x.update();self.right=Some(x);self.update();}fn rotate_left(&mut self){let mut x=self.right.take().unwrap();let b=x.left.take();swap(self,&mut x);x.right=b;x.update();self.left=Some(x);self.update();}fn balance(&mut self){if height(&self.left).abs_diff(height(&self.right))<=1{self.update();return;}if height(&self.left)>height(&self.right){let left_child=self.left.as_mut().unwrap();if height(&left_child.left)height(&right_child.right){right_child.rotate_right();}self.rotate_left();}}#[allow(unused)]fn verify_balance(&self){if height(&self.left).abs_diff(height(&self.right))>1{panic!("height: {} {}",height(&self.left),height(&self.right));}if let Some(left)=&self.left{left.verify_balance();}if let Some(right)=&self.right{right.verify_balance();}}#[allow(unused)]fn verify_height(&self){if self.left.is_none()&&self.right.is_none(){assert_eq!(self.height,1);return;}if let Some(left)=&self.left{left.verify_height();}if let Some(right)=&self.right{right.verify_height();}assert_eq!(self.height,1+height(&self.left).max(height(&self.right)),"{} vs height: {} {}",self.height,height(&self.left),height(&self.right));}fn list_sub(self,ret:&mut Vec){if let Some(left)=self.left{left.list_sub(ret);}ret.push(self.value);if let Some(right)=self.right{right.list_sub(ret);}}}implDisplay for Node{fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{if let Some(left)=&self.left{write!(f,"{}",left)?;}write!(f,"{}, ",self.value)?;if let Some(right)=&self.right{write!(f,"{}",right)?;}Ok(())}}fn len(tree:&Tree)->usize{tree.as_ref().map_or(0,|t|t.len)}fn height(tree:&Tree)->u8{tree.as_ref().map_or(0,|t|t.height)}fn merge(left:Tree,right:Tree)->Tree{match(left.is_some(),right.is_some()){(true,true)=>{let(_,center,rhs)=split_delete(right.unwrap(),0);Some(merge_with_root(left,center,rhs))}(false,_)=>right,(_,false)=>left,}}fn merge_with_root(mut left:Tree,mut center:Box>,mut right:Tree,)->Box>{if height(&left).abs_diff(height(&right))<=1{center.left=left;center.right=right;center.update();center}else if height(&left)(mut root:Box>,index:usize)->(Tree,Box>,Tree){debug_assert!((0..root.len).contains(&index));let left=root.left.take();let right=root.right.take();let lsize=len(&left);match lsize.cmp(&index){Ordering::Equal=>(left,root,right),Ordering::Less=>{let mut ret=split_delete(right.unwrap(),index-lsize-1);ret.0=Some(merge_with_root(left,root,ret.0));ret}Ordering::Greater=>{let mut ret=split_delete(left.unwrap(),index);ret.2=Some(merge_with_root(ret.2,root,right));ret}}}fn split(tree:Tree,index:usize)->(Tree,Tree){let Some(root)=tree else{return(None,None);};if index==0{(None,Some(root))}else if root.len==index{(Some(root),None)}else{let(left,center,right)=split_delete(root,index);(left,Some(merge_with_root(None,center,right)))}}fn lower_bound(tree:&Tree,value:&T)->usize{let Some(tree)=tree else{return 0;};if value<=&tree.value{lower_bound(&tree.left,value)}else{len(&tree.left)+1+lower_bound(&tree.right,value)}}fn upper_bound(tree:&Tree,value:&T)->usize{let Some(tree)=tree else{return 0;};if value>=&tree.value{len(&tree.left)+1+upper_bound(&tree.right,value)}else{upper_bound(&tree.left,value)}}fn count(tree:&Tree,value:&T)->usize{upper_bound(tree,value)-lower_bound(tree,value)}fn get(tree:&Tree,index:usize)->Option<&T>{if len(tree)<=index{return None;}let Some(tree)=tree else{return None;};let left_len=len(&tree.left);match index.cmp(&left_len){Ordering::Less=>get(&tree.left,index),Ordering::Equal=>Some(&tree.value),Ordering::Greater=>get(&tree.right,index-left_len-1),}}#[derive(Debug)]pub struct AVL{root:Tree,multi:bool,}implDisplay for AVL{fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{if let Some(root)=&self.root{write!(f,"{}",root)}else{write!(f,"Empty")}}}implAVL{pub fn new(multi:bool)->Self{Self{root:None,multi}}pub fn len(&self)->usize{len(&self.root)}pub fn height(&self)->u8{height(&self.root)}pub fn is_empty(&self)->bool{self.root.is_none()}pub fn lower_bound(&self,value:&T)->usize where T:PartialOrd,{lower_bound(&self.root,value)}pub fn upper_bound(&self,value:&T)->usize where T:PartialOrd,{upper_bound(&self.root,value)}pub fn get(&self,index:usize)->Option<&T>{get(&self.root,index)}pub fn split_off(&mut self,index:usize)->Self{assert!(index<=self.len());let(left,right)=split(self.root.take(),index);self.root=left;Self{root:right,multi:self.multi}}pub fn insert_by_index(&mut self,index:usize,value:T){assert!(index<=self.len());let other=self.split_off(index);self.root=Some(merge_with_root(self.root.take(),Box::new(Node::new(value)),other.root,))}pub fn insert(&mut self,value:T)where T:PartialOrd,{if!self.multi{if self.count(&value)>0{return;}}let index=self.lower_bound(&value);self.insert_by_index(index,value);}pub fn erase_index(&mut self,index:usize)->Option{if indexbool where T:PartialOrd,{if self.count(value)==0{return false;}let index=self.lower_bound(value);let ret=self.erase_index(index);ret.is_some()}pub fn count(&self,value:&T)->usize where T:PartialOrd,{count(&self.root,value)}pub fn into_vec(self)->Vec{let mut ret=Vec::with_capacity(self.len());if let Some(root)=self.root{root.list_sub(&mut ret);}ret}}} } pub(crate) mod macros { pub mod avl {} } pub(crate) mod prelude {pub use crate::__cargo_equip::crates::*;} mod preludes { pub mod avl {} } }