結果

問題 No.777 再帰的ケーキ
ユーザー pekempeypekempey
提出日時 2018-12-24 18:21:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,849 bytes
コンパイル時間 368 ms
コンパイル使用メモリ 38,272 KB
実行使用メモリ 13,284 KB
最終ジャッジ日時 2023-10-26 03:03:09
合計ジャッジ時間 2,108 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
12,112 KB
testcase_01 AC 2 ms
12,112 KB
testcase_02 AC 2 ms
12,112 KB
testcase_03 AC 2 ms
12,112 KB
testcase_04 AC 2 ms
12,112 KB
testcase_05 AC 2 ms
12,112 KB
testcase_06 AC 2 ms
12,112 KB
testcase_07 AC 2 ms
12,112 KB
testcase_08 AC 2 ms
12,112 KB
testcase_09 AC 2 ms
12,112 KB
testcase_10 AC 2 ms
12,112 KB
testcase_11 AC 2 ms
12,112 KB
testcase_12 AC 2 ms
12,112 KB
testcase_13 AC 2 ms
12,112 KB
testcase_14 AC 1 ms
12,112 KB
testcase_15 AC 2 ms
12,112 KB
testcase_16 AC 2 ms
12,112 KB
testcase_17 AC 2 ms
12,112 KB
testcase_18 AC 2 ms
12,112 KB
testcase_19 AC 2 ms
12,112 KB
testcase_20 AC 2 ms
12,112 KB
testcase_21 AC 2 ms
12,116 KB
testcase_22 AC 2 ms
12,116 KB
testcase_23 AC 2 ms
12,112 KB
testcase_24 AC 2 ms
12,112 KB
testcase_25 AC 3 ms
12,116 KB
testcase_26 AC 2 ms
12,116 KB
testcase_27 AC 2 ms
12,112 KB
testcase_28 AC 31 ms
13,284 KB
testcase_29 AC 30 ms
13,284 KB
testcase_30 AC 35 ms
13,284 KB
testcase_31 AC 35 ms
13,284 KB
testcase_32 AC 23 ms
13,284 KB
testcase_33 AC 12 ms
12,112 KB
testcase_34 AC 17 ms
12,648 KB
testcase_35 AC 30 ms
13,284 KB
testcase_36 AC 24 ms
13,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <unistd.h>

struct P {
    int a, b, c;
};

int n;
struct P a[200000];
long long bit[200001];

long long max(long long x, long long y) {
    return x > y ? x : y;
}

void update(int k, long long v) {
    for (int i = k + 1; i <= 200000 && bit[i] < v; i += i & -i) {
        bit[i] = v;
    }
}

long long query(int k) {
    long long res = 0;
    for (int i = k; i > 0; i -= i & -i) {
        res = max(res, bit[i]);
    }
    return res;
}

template<class T, class F>
void mysort(T *a, int n, F f) {
    for (int i = 0; i < 32; i += 16) {
        static int c[65537];
        static T t[200000];
        for (int j = 0; j < 65537; j++) {
            c[j] = 0;
        }
        for (int j = 0; j < n; j++) {
            c[(f(a[j]) >> i & 0xffff) + 1]++;
            t[j] = a[j];
        }
        for (int j = 0; j < 65536; j++) {
            c[j + 1] += c[j];
        }
        for (int j = 0; j < n; j++) {
            a[c[f(t[j]) >> i & 0xffff]++] = t[j];
        }
    }
}

int i32() {
    int n, c;
    while ((c = getchar_unlocked()) < '0');
    n = c - '0';
    while ((c = getchar_unlocked()) >= '0') {
        n = n * 10 + (c - '0');
    }
    return n;
}

int main() {
    int n = i32();
    for (int i = 0; i < n; i++) {
        a[i].a = i32();
        a[i].b = i32();
        a[i].c = i32();
    }
    mysort(a, n, [](struct P x) { return x.b; });
    {
        int k = -1;
        int p = -1;
        for (int i = 0; i < n; i++) {
            k += p != a[i].b;
            p = a[i].b;
            a[i].b = k;
        }
    }
    mysort(a, n, [](struct P x) { return 2147483647 - x.b; });
    mysort(a, n, [](struct P x) { return x.a; });
    for (int i = 0; i < n; i++) {
        update(a[i].b, query(a[i].b) + a[i].c);
    }
    printf("%lld\n", query(200000));
}

0