結果

問題 No.649 ここでちょっとQK!
ユーザー tabataba
提出日時 2024-07-31 11:08:13
言語 Rust
(1.77.0)
結果
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
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 250 ms
6,944 KB
testcase_04 AC 79 ms
9,088 KB
testcase_05 AC 100 ms
9,088 KB
testcase_06 AC 97 ms
9,088 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 63 ms
6,944 KB
testcase_13 AC 59 ms
6,940 KB
testcase_14 AC 59 ms
6,944 KB
testcase_15 AC 66 ms
6,944 KB
testcase_16 AC 53 ms
6,940 KB
testcase_17 AC 64 ms
6,940 KB
testcase_18 AC 73 ms
6,940 KB
testcase_19 AC 79 ms
6,940 KB
testcase_20 AC 87 ms
6,940 KB
testcase_21 AC 99 ms
6,944 KB
testcase_22 AC 104 ms
6,940 KB
testcase_23 AC 112 ms
6,940 KB
testcase_24 AC 124 ms
6,940 KB
testcase_25 AC 123 ms
6,944 KB
testcase_26 AC 132 ms
6,940 KB
testcase_27 AC 1 ms
6,944 KB
testcase_28 AC 1 ms
6,940 KB
testcase_29 AC 1 ms
6,940 KB
testcase_30 AC 60 ms
6,944 KB
testcase_31 AC 56 ms
6,940 KB
testcase_32 AC 1 ms
6,940 KB
testcase_33 AC 1 ms
6,944 KB
testcase_34 AC 1 ms
6,940 KB
testcase_35 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
  |     ^^^^^^^^^^^^^^^^^^^^^^^

ソースコード

diff #

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()
}
0