結果

問題 No.2422 regisys?
ユーザー InTheBloomInTheBloom
提出日時 2024-03-06 08:00:11
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 326 ms / 2,000 ms
コード長 1,673 bytes
コンパイル時間 1,719 ms
コンパイル使用メモリ 186,476 KB
実行使用メモリ 17,188 KB
最終ジャッジ日時 2024-03-06 08:00:22
合計ジャッジ時間 10,105 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,548 KB
testcase_01 AC 1 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 1 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 1 ms
6,548 KB
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 1 ms
6,548 KB
testcase_08 AC 1 ms
6,548 KB
testcase_09 AC 1 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 2 ms
6,548 KB
testcase_12 AC 1 ms
6,548 KB
testcase_13 AC 2 ms
6,548 KB
testcase_14 AC 1 ms
6,548 KB
testcase_15 AC 2 ms
6,548 KB
testcase_16 AC 2 ms
6,548 KB
testcase_17 AC 2 ms
6,548 KB
testcase_18 AC 2 ms
6,548 KB
testcase_19 AC 1 ms
6,548 KB
testcase_20 AC 2 ms
6,548 KB
testcase_21 AC 1 ms
6,548 KB
testcase_22 AC 1 ms
6,548 KB
testcase_23 AC 2 ms
6,548 KB
testcase_24 AC 2 ms
6,548 KB
testcase_25 AC 1 ms
6,548 KB
testcase_26 AC 2 ms
6,548 KB
testcase_27 AC 2 ms
6,548 KB
testcase_28 AC 1 ms
6,548 KB
testcase_29 AC 1 ms
6,548 KB
testcase_30 AC 1 ms
6,548 KB
testcase_31 AC 96 ms
8,380 KB
testcase_32 AC 156 ms
8,140 KB
testcase_33 AC 80 ms
8,380 KB
testcase_34 AC 70 ms
6,548 KB
testcase_35 AC 93 ms
8,224 KB
testcase_36 AC 116 ms
6,664 KB
testcase_37 AC 167 ms
8,320 KB
testcase_38 AC 134 ms
6,548 KB
testcase_39 AC 88 ms
6,548 KB
testcase_40 AC 52 ms
7,228 KB
testcase_41 AC 83 ms
6,708 KB
testcase_42 AC 159 ms
16,592 KB
testcase_43 AC 108 ms
7,980 KB
testcase_44 AC 184 ms
16,532 KB
testcase_45 AC 149 ms
15,696 KB
testcase_46 AC 194 ms
15,548 KB
testcase_47 AC 127 ms
8,508 KB
testcase_48 AC 169 ms
16,708 KB
testcase_49 AC 165 ms
13,496 KB
testcase_50 AC 143 ms
17,188 KB
testcase_51 AC 269 ms
16,780 KB
testcase_52 AC 77 ms
8,508 KB
testcase_53 AC 206 ms
16,376 KB
testcase_54 AC 272 ms
17,168 KB
testcase_55 AC 188 ms
16,888 KB
testcase_56 AC 200 ms
11,496 KB
testcase_57 AC 309 ms
16,684 KB
testcase_58 AC 326 ms
16,776 KB
testcase_59 AC 309 ms
16,752 KB
testcase_60 AC 309 ms
16,704 KB
testcase_61 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main () {
    int N, M; readln.read(N, M);
    auto A = readln.split.to!(int[]);
    auto B = readln.split.to!(int[]);

    int[] mma, non_mma;

    foreach (i; 0..M) {
        int T, C; readln.read(T, C);

        if (T == 0) non_mma ~= C;
        if (T == 1) mma ~= C;
    }

    solve(N, M, A, B, mma, non_mma);
}

void solve (int N, int M, int[] A, int[] B, int[] mma, int[] non_mma) {
    auto items = new Tuple!(int, int, int)[](N);
    foreach (i; 0..N) {
        items[i] = tuple(i, A[i], B[i]);
    }

    items.sort!"a[1] < b[1]";
    non_mma.sort;

    auto used = new bool[](N);

    {
        BinaryHeap!(Tuple!(int, int)[], "a[1] < b[1]") PQ = [];
        // rangeだけ使う
        auto r = items;

        foreach (v; non_mma) {
            while (!r.empty && r.front[1] <= v) {
                PQ.insert(tuple(r.front[0], r.front[2]));
                r.popFront;
            }

            if (PQ.empty) continue;
            used[PQ.front[0]] = true;
            PQ.removeFront;
        }
    }

    mma.sort;
    BinaryHeap!(Tuple!(int, int)[], "b[1] < a[1]") PQ = [];
    foreach (i; 0..N) {
        if (used[items[i][0]]) continue;
        PQ.insert(tuple(items[i][0], items[i][2]));
    }

    foreach (v; mma) {
        if (PQ.empty) break;
        if (v < PQ.front[1]) continue;
        used[PQ.front[0]] = true;
        PQ.removeFront;
    }

    int ans = 0;
    foreach (i; 0..N) if (!used[i]) ans++;

    writeln(ans);
}

void read (T...) (string S, ref T args) {
    import std.conv : to;
    import std.array : split;
    auto buf = S.split;
    foreach (i, ref arg; args) {
        arg = buf[i].to!(typeof(arg));
    }
}
0