結果

問題 No.2804 Fixer And Ratism
ユーザー NakLon131NakLon131
提出日時 2024-07-12 22:41:53
言語 Rust
(1.77.0)
結果
RE  
実行時間 -
コード長 2,328 bytes
コンパイル時間 14,790 ms
コンパイル使用メモリ 378,356 KB
実行使用メモリ 7,296 KB
最終ジャッジ日時 2024-07-12 22:42:28
合計ジャッジ時間 16,816 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 22 ms
5,376 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 3 ms
5,376 KB
testcase_10 RE -
testcase_11 AC 39 ms
5,376 KB
testcase_12 RE -
testcase_13 AC 8 ms
5,376 KB
testcase_14 AC 25 ms
5,376 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 12 ms
5,376 KB
testcase_18 RE -
testcase_19 AC 2 ms
5,376 KB
testcase_20 RE -
testcase_21 AC 48 ms
5,376 KB
testcase_22 RE -
testcase_23 AC 54 ms
7,296 KB
testcase_24 RE -
testcase_25 AC 54 ms
7,296 KB
testcase_26 RE -
testcase_27 RE -
testcase_28 AC 54 ms
7,168 KB
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 AC 49 ms
7,168 KB
testcase_33 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    input!{
		n: i64, 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!{
			num: i64,
		}

		if num == 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 num == 2 {
			input!{
				x: i64,
			}

			// 定員を減らす
			nn -= x;

			// 定員を超えていたら取り出す
			dropout(nn, &mut mp, &mut mp_rev, &mut bst);
		}
		else {
			input!{
				s: String, x: i64,
			}

			// 定員を増やす
			nn += x;

			// その人を優遇する 取り出して更新
			update_info(s, &mut mp, &mut mp_rev, &mut bst);
		}
	}

}

fn update_info(s: String, mp: &mut BTreeMap<String, usize>, mp_rev: &mut BTreeMap<usize, String>, st: &mut BTreeSet<usize>) {
	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: i64, mp: &mut BTreeMap<String, usize>, mp_rev: &mut BTreeMap<usize, String>, st: &mut BTreeSet<usize>){
	let mut now_sz = mp.len() as i64;
	
	let mut ret = Vec::new();
	while now_sz > max(n, 0) {
		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,
};
0