結果

問題 No.649 ここでちょっとQK!
ユーザー akakimidoriakakimidori
提出日時 2019-08-01 11:06:15
言語 Rust
(1.77.0)
結果
AC  
実行時間 37 ms / 3,000 ms
コード長 1,217 bytes
コンパイル時間 2,648 ms
コンパイル使用メモリ 135,452 KB
実行使用メモリ 11,792 KB
最終ジャッジ日時 2023-09-18 17:19:11
合計ジャッジ時間 3,170 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 8 ms
4,376 KB
testcase_04 AC 34 ms
11,740 KB
testcase_05 AC 34 ms
11,632 KB
testcase_06 AC 35 ms
11,792 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 16 ms
4,608 KB
testcase_13 AC 15 ms
4,660 KB
testcase_14 AC 15 ms
4,668 KB
testcase_15 AC 18 ms
4,700 KB
testcase_16 AC 14 ms
4,676 KB
testcase_17 AC 18 ms
4,856 KB
testcase_18 AC 22 ms
6,888 KB
testcase_19 AC 24 ms
6,820 KB
testcase_20 AC 26 ms
6,908 KB
testcase_21 AC 28 ms
7,116 KB
testcase_22 AC 30 ms
7,092 KB
testcase_23 AC 32 ms
7,116 KB
testcase_24 AC 33 ms
7,160 KB
testcase_25 AC 35 ms
7,380 KB
testcase_26 AC 37 ms
7,400 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 12 ms
4,376 KB
testcase_31 AC 12 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::str::SplitWhitespace;
use std::str::FromStr;
use std::io::BufWriter;
use std::io::Write;
use std::io::Read;
struct Scanner<'a> {
    it: SplitWhitespace<'a>,
}

impl<'a> Scanner<'a> {
    pub fn next<T: FromStr>(&mut self) -> T {
        self.it.next().unwrap().parse::<T>().ok().unwrap()
    }
}

use std::collections::BinaryHeap;
use std::cmp::Reverse;

fn run() {
    let s = {
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    };
    let mut sc = Scanner {it: s.split_whitespace()};
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    let q: usize = sc.next();
    let k: usize = sc.next();
    let mut small = BinaryHeap::new();
    let mut large = BinaryHeap::new();
    for _ in 0..q {
        let op: u8 = sc.next();
        if op == 1 {
            let v: u64 = sc.next();
            small.push(v);
            if small.len() >= k {
                large.push(Reverse(small.pop().unwrap()));
            }
        } else if let Some(Reverse(v)) = large.pop() {
            writeln!(out, "{}", v).unwrap();
        } else {
            writeln!(out, "-1").unwrap();
        }
    }
}

fn main() {
    run();
}
0