結果

問題 No.649 ここでちょっとQK!
ユーザー ngtkanangtkana
提出日時 2023-10-06 13:55:06
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 2,414 bytes
コンパイル時間 1,135 ms
コンパイル使用メモリ 155,404 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-10-06 13:55:13
合計ジャッジ時間 6,930 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 274 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 54 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use input::input_array;
use input::input_vec;
use std::cmp::Reverse;
use std::collections::BinaryHeap;

fn main() {
    let [q, k] = input_array::<usize, 2>();
    let k = k - 1;
    let mut topk = BinaryHeap::<Reverse<usize>>::new();
    let mut others = BinaryHeap::<usize>::new();
    for _ in 0..q {
        let query = input_vec::<usize>();
        match query[0] {
            1 => {
                let x = query[1];
                topk.push(Reverse(x));
                if k < topk.len() {
                    others.push(topk.pop().unwrap().0);
                }
            }
            2 => {
                let ans = others.pop().map_or_else(|| -1, |x| x as isize);
                println!("{}", ans);
            }
            _ => unreachable!(),
        }
    }
}
// input {{{
#[allow(dead_code)]
mod input {
    use std::cell::Cell;
    use std::convert::TryFrom;
    use std::io::stdin;
    use std::io::BufRead;
    use std::io::BufReader;
    use std::io::Lines;
    use std::io::Stdin;
    use std::str::FromStr;
    use std::sync::Mutex;
    use std::sync::Once;
    type Server = Mutex<Lines<BufReader<Stdin>>>;
    static ONCE: Once = Once::new();
    pub struct Lazy(Cell<Option<Server>>);
    unsafe impl Sync for Lazy {}
    fn line() -> String {
        static SYNCER: Lazy = Lazy(Cell::new(None));
        ONCE.call_once(|| {
            SYNCER
                .0
                .set(Some(Mutex::new(BufReader::new(stdin()).lines())));
        });
        unsafe {
            (*SYNCER.0.as_ptr())
                .as_ref()
                .unwrap()
                .lock()
                .unwrap()
                .next()
                .unwrap()
                .unwrap()
        }
    }
    pub trait ForceFromStr: FromStr {
        fn force_from_str(s: &str) -> Self;
    }
    impl<T, E> ForceFromStr for T
    where
        T: FromStr<Err = E>,
        E: std::fmt::Debug,
    {
        fn force_from_str(s: &str) -> Self { s.parse().unwrap() }
    }
    pub fn input_array<T: ForceFromStr, const N: usize>() -> [T; N]
    where
        T: std::fmt::Debug,
    {
        <[_; N]>::try_from(input_vec()).unwrap()
    }
    pub fn input_vec<T: ForceFromStr>() -> Vec<T> {
        line()
            .split_whitespace()
            .map(T::force_from_str)
            .collect::<Vec<_>>()
    }
    pub fn input<T: ForceFromStr>() -> T { T::force_from_str(&line()) }
}
// }}}
0