結果

問題 No.3126 Dual Query Problem
ユーザー NakLon131
提出日時 2025-04-26 10:36:14
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 290 ms / 2,000 ms
コード長 1,906 bytes
コンパイル時間 11,834 ms
コンパイル使用メモリ 386,716 KB
実行使用メモリ 8,160 KB
最終ジャッジ日時 2025-06-20 02:53:12
合計ジャッジ時間 22,761 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    input!{
		n: usize, q: usize,
		mut x: [usize; n],
	}

	// 何回操作が必要かを数える
	let cnt = calc_controls(&x);

	// q回を超えたらNG
	if cnt > q {
		println!("No");
		return;
	}
	println!("Yes");

	// q回以下なら、実際に操作する
	exec_controls(&x, q);
}

fn calc_controls(x: &Vec<usize>) -> usize {
	let mut cnt = 0;

	// 始めてでてきた数字は2回
	// 2回目以降は1回と数える
	// 出てきた数字をセット
	let mut mp = HashMap::new();
	for &xx in x {
		if !mp.contains_key(&xx) {
			mp.insert(xx, 1);
			cnt += 2;
		}
		else {
			cnt += 1;
		}
	}	
	cnt
}

fn exec_controls(x: &Vec<usize>, q: usize){
	let mut cnt = 0;

	// 出てきた数字を順番にセット
	let mut idx = 1;
	let mut mp = HashMap::new();
	for &xx in x {
		if !mp.contains_key(&xx) {
			println!("1 {} {}", idx, xx);
			mp.insert(xx, idx);
			idx += 1;
			cnt += 1;
		}
	}

	// クエリ順に出力
	for &xx in x {
		println!("2 {}", *mp.get(&xx).unwrap());
		cnt += 1;
	}

	// q回より少ない分を適当にセット
	for _ in cnt..q {
		println!("1 {} {}", 1, 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,
};
// 配列のスペース区切り出力
#[allow(unused)]
fn vec_print<T: std::fmt::Display>(vec: &Vec<T>) {
	let sz = vec.len();
	for i in 0..sz-1 {
		print!("{} ", vec[i]);
	}
	println!("{}", vec[sz-1]);
}
0