fn main() { input!{ n: usize, q: usize, } // 使用可能台数(可変) let mut nn = n; // 取り出す順(順序つき集合(値のみ)) let mut bst = BTreeSet::new(); // 在籍情報(人と値) (値と人) let mut mp = BTreeMap::new(); let mut mp_rev = BTreeMap::new(); // クエリ毎に処理 for _ in 0..q { input!{ nm: usize, } if nm == 1 { input!{ s: String, t: usize, } // 人を追加 bst.insert(t); mp.insert(s.clone(), t); mp_rev.insert(t, s); // 定員を超えていたら取り出す dropout(nn, &mut mp, &mut mp_rev, &mut bst); } else if nm == 2 { input!{ x: usize, } // 定員を減らす nn -= x; // 定員を超えていたら取り出す dropout(nn, &mut mp, &mut mp_rev, &mut bst); } else { input!{ s: String, x: usize, } // 定員を増やす nn += x; // その人を優遇する 取り出して更新 update_info(s, &mut mp, &mut mp_rev, &mut bst); } } } fn update_info(s: String, mp: &mut BTreeMap, mp_rev: &mut BTreeMap, st: &mut BTreeSet) { let mut now_t = *mp.get(&s).unwrap(); mp.remove(&s); mp_rev.remove(&now_t); st.remove(&now_t); now_t += 100_000; mp.insert(s.clone(), now_t); mp_rev.insert(now_t, s); st.insert(now_t); } fn dropout(n: usize, mp: &mut BTreeMap, mp_rev: &mut BTreeMap, st: &mut BTreeSet){ let mut now_sz = mp.len(); let mut ret = Vec::new(); while now_sz > n { let (now_t, now_s) = mp_rev.pop_first().unwrap(); st.pop_first(); mp.remove(&now_s); ret.push((now_t % 100_000, now_s)); now_sz -= 1; } ret.sort(); for i in 0..ret.len() { println!("{}", ret[i].1); } } // const MOD17: usize = 1000000007; // const MOD93: usize = 998244353; // const INF: usize = 1 << 60; // let dx = vec![!0, 0, 1, 0]; // 上左下右 // let dy = vec![0, !0, 0, 1]; // 上左下右 // let d = vec!{(!0, 0), (0, !0), (1, 0), (0, 1)}; // 上左下右 #[allow(unused)] use proconio::{input, marker::Chars, marker::Usize1}; #[allow(unused)] use std::{ mem::swap, cmp::min, cmp::max, cmp::Reverse, collections::HashSet, collections::BTreeSet, collections::HashMap, collections::BTreeMap, collections::BinaryHeap, collections::VecDeque, iter::FromIterator, };