結果

問題 No.777 再帰的ケーキ
ユーザー pekempey
提出日時 2018-12-24 18:27:35
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 1,976 bytes
コンパイル時間 352 ms
コンパイル使用メモリ 38,580 KB
実行使用メモリ 19,072 KB
最終ジャッジ日時 2024-09-25 11:02:12
合計ジャッジ時間 2,015 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:69:9: warning: ignoring return value of ‘ssize_t read(int, void*, size_t)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   69 |     read(STDIN_FILENO, buf, sizeof(buf));
      |     ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <unistd.h>
#include <fcntl.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];
        }
    }
}

char buf[200000 * 33 + 100];
int k = 0;

int i32() {
    int res = 0;
    while (buf[k] < '0') k++;
    while (buf[k] >= '0') {
        res = res * 10 + (buf[k] - '0');
        k++;
    }
    return res;
}

int main() {
    fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);
    read(STDIN_FILENO, buf, sizeof(buf));
    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