結果

問題 No.649 ここでちょっとQK!
ユーザー nanaenanae
提出日時 2018-02-10 00:27:49
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 225 ms / 3,000 ms
コード長 1,666 bytes
コンパイル時間 1,933 ms
コンパイル使用メモリ 106,700 KB
実行使用メモリ 5,432 KB
最終ジャッジ日時 2023-09-03 18:42:04
合計ジャッジ時間 7,141 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 180 ms
4,376 KB
testcase_04 AC 222 ms
5,424 KB
testcase_05 AC 188 ms
5,432 KB
testcase_06 AC 206 ms
5,424 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 104 ms
4,528 KB
testcase_13 AC 103 ms
4,540 KB
testcase_14 AC 103 ms
4,524 KB
testcase_15 AC 109 ms
4,548 KB
testcase_16 AC 101 ms
4,508 KB
testcase_17 AC 121 ms
4,612 KB
testcase_18 AC 133 ms
4,724 KB
testcase_19 AC 146 ms
4,668 KB
testcase_20 AC 157 ms
4,824 KB
testcase_21 AC 167 ms
4,788 KB
testcase_22 AC 179 ms
4,852 KB
testcase_23 AC 190 ms
4,780 KB
testcase_24 AC 201 ms
5,128 KB
testcase_25 AC 213 ms
5,072 KB
testcase_26 AC 225 ms
5,036 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 89 ms
4,432 KB
testcase_31 AC 95 ms
4,556 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;

void main() {
    int q, k;
    scan(q, k);

    import std.container;

    auto maxh = new BinaryHeap!(Array!long, "a < b")();
    auto minh = new BinaryHeap!(Array!long, "a > b")();

    foreach (i ; 0 .. q) {
        auto line = readln.split.to!(long[]);

        if (line[0] == 1) {
            if (maxh.length < k) {
                maxh.insert(line[1]);
            }
            else {
                if (maxh.front < line[1]) {
                    minh.insert(line[1]);
                }
                else {
                    minh.insert(maxh.front);
                    maxh.removeFront();
                    maxh.insert(line[1]);
                }
            }
        }
        else {
            if (maxh.length < k) {
                writeln(-1);
            }
            else {
                writeln(maxh.front);
                maxh.removeFront();
                if (!minh.empty) {
                    maxh.insert(minh.front);
                    minh.removeFront();
                }
            }
        }
    }
}




void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}
0