結果
| 問題 |
No.649 ここでちょっとQK!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-07-31 11:08:13 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 250 ms / 3,000 ms |
| コード長 | 1,502 bytes |
| コンパイル時間 | 12,877 ms |
| コンパイル使用メモリ | 386,820 KB |
| 実行使用メモリ | 9,088 KB |
| 最終ジャッジ日時 | 2024-07-31 11:08:30 |
| 合計ジャッジ時間 | 16,696 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
コンパイルメッセージ
warning: unused imports: `HashMap`, `HashSet`, `VecDeque`
--> src/main.rs:2:29
|
2 | collections::{BTreeSet, HashMap, HashSet, VecDeque},
| ^^^^^^^ ^^^^^^^ ^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
warning: unused import: `proconio::marker::Chars`
--> src/main.rs:8:5
|
8 | use proconio::marker::Chars;
| ^^^^^^^^^^^^^^^^^^^^^^^
ソースコード
use std::{
collections::{BTreeSet, HashMap, HashSet, VecDeque},
fmt::Debug,
io::stdin,
str::FromStr,
};
use proconio::marker::Chars;
fn main() {
// proconio::input! {
// q: usize,
// k: usize,
// }
let x = read::<u64>();
let (q, k) = (x[0], x[1]);
let k = k as usize;
let mut query = (0..q)
.flat_map(|_| read::<u64>())
.enumerate()
.map(|v| (v.1, v.0));
let mut s = BTreeSet::new();
let mut t = BTreeSet::new();
while let Some(q) = query.next() {
match q.0 {
1 => {
let val = query.next().unwrap();
if s.len() == k {
t.insert(s.pop_last().unwrap());
t.insert(val);
s.insert(t.pop_first().unwrap());
} else {
s.insert(val);
}
}
2 => {
if s.len() < k as usize {
println!("-1");
} else {
println!("{}", s.pop_last().unwrap().0);
if let Some(x) = t.pop_first() {
s.insert(x);
}
}
}
_ => unreachable!(),
}
}
}
fn read<T>() -> Vec<T>
where
T: FromStr,
<T as std::str::FromStr>::Err: Debug,
{
let mut s = String::new();
stdin().read_line(&mut s).unwrap();
s.split(' ').map(|v| v.trim().parse().expect(v)).collect()
}