結果

問題 No.777 再帰的ケーキ
ユーザー nebukuro09nebukuro09
提出日時 2018-12-25 04:16:22
言語 D
(dmd 2.107.1)
結果
WA  
実行時間 -
コード長 1,864 bytes
コンパイル時間 987 ms
コンパイル使用メモリ 120,988 KB
実行使用メモリ 47,604 KB
最終ジャッジ日時 2023-09-03 21:45:19
合計ジャッジ時間 8,061 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 WA -
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,384 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 WA -
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 5 ms
4,376 KB
testcase_22 AC 5 ms
4,376 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 6 ms
4,380 KB
testcase_26 AC 5 ms
4,376 KB
testcase_27 WA -
testcase_28 AC 522 ms
43,932 KB
testcase_29 AC 507 ms
44,000 KB
testcase_30 AC 532 ms
44,048 KB
testcase_31 AC 541 ms
44,344 KB
testcase_32 AC 387 ms
47,604 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 405 ms
43,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto N = readln.chomp.to!int;
    auto A = N.iota.map!(_ => readln.split.map!(to!long).array).array;

    long[long] comp;
    auto B = A.map!(a => a[1]).array.sort().uniq().array;
    auto M = B.length.to!int;
    foreach (i; 0..M) comp[B[i]] = i;

    foreach (i; 0..N) A[i][1] = comp[A[i][1]];
    A.sort!"a[0] == b[0] ? a[1] < b[1] : a[0] > b[0]"();

    auto st = new SegmentTree!(long, max, 0L)(M);


    foreach (i; 0..N) {
        auto v = st.query(A[i][1].to!int+1, M-1);
        st.assign(A[i][1].to!int, v + A[i][2]);
    }

    st.query(0, M-1).writeln;
}


class SegmentTree(T, alias op, T e) {
    T[] table;
    int size;
    int offset;

    this(int n) {
        size = 1;
        while (size <= n) size <<= 1;
        size <<= 1;
        table = new T[](size);
        fill(table, e);
        offset = size / 2;
    }

    void assign(int pos, T val) {
        pos += offset;
        table[pos] = val;
        while (pos > 1) {
            pos /= 2;
            table[pos] = op(table[pos*2], table[pos*2+1]);
        }
    }

    void add(int pos, T val) {
        pos += offset;
        table[pos] += val;
        while (pos > 1) {
            pos /= 2;
            table[pos] = op(table[pos*2], table[pos*2+1]);
        }
    }

    T query(int l, int r) {
        if (r < l) return e;
        return query(l, r, 1, 0, offset-1);
    }

    T query(int l, int r, int i, int a, int b) {
        if (b < l || r < a) {
            return e;
        } else if (l <= a && b <= r) {
            return table[i];
        } else {
            return op(query(l, r, i*2, a, (a+b)/2), query(l, r, i*2+1, (a+b)/2+1, b));
        }
    }
}
0