結果

問題 No.777 再帰的ケーキ
ユーザー PachicobuePachicobue
提出日時 2018-12-24 02:27:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,852 bytes
コンパイル時間 2,435 ms
コンパイル使用メモリ 221,324 KB
実行使用メモリ 59,928 KB
最終ジャッジ日時 2023-10-26 02:55:33
合計ジャッジ時間 9,490 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 WA -
testcase_19 AC 2 ms
4,348 KB
testcase_20 WA -
testcase_21 AC 4 ms
4,348 KB
testcase_22 AC 4 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 5 ms
4,348 KB
testcase_26 AC 4 ms
4,348 KB
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 687 ms
59,928 KB
testcase_29 AC 689 ms
59,928 KB
testcase_30 AC 720 ms
59,928 KB
testcase_31 AC 680 ms
59,928 KB
testcase_32 AC 296 ms
38,016 KB
testcase_33 AC 55 ms
14,588 KB
testcase_34 AC 78 ms
16,104 KB
testcase_35 AC 387 ms
38,016 KB
testcase_36 AC 295 ms
38,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << (x) << std::endl
using ll = long long;
using ull = unsigned long long;
template <typename T>
constexpr T INF = std::numeric_limits<T>::max() / 10;
struct Cake
{
    ll A, B, C;
    bool operator<(const Cake& c) const { return A != c.A ? A < c.A : B != c.B ? B < c.B : C > c.C; }
};
constexpr std::size_t PC(ull v) { return v = (v & 0x5555555555555555ULL) + (v >> 1 & 0x5555555555555555ULL), v = (v & 0x3333333333333333ULL) + (v >> 2 & 0x3333333333333333ULL), v = (v + (v >> 4)) & 0x0F0F0F0F0F0F0F0FULL, static_cast<std::size_t>(v * 0x0101010101010101ULL >> 56 & 0x7f); }
constexpr std::size_t LG(ull v) { return v == 0 ? 0 : (v--, v |= (v >> 1), v |= (v >> 2), v |= (v >> 4), v |= (v >> 8), v |= (v >> 16), v |= (v >> 32), PC(v)); }
constexpr ull SZ(const ull v) { return 1ULL << LG(v); }
template <typename Monoid>
class SegmentTree
{
public:
    using BaseMonoid = Monoid;
    using T = typename Monoid::T;
    SegmentTree(const std::size_t n) : data_num(n), half(SZ(n)), value(half << 1, Monoid::id()) {}
    T get(const std::size_t a) const { return value[a + half]; }
    void set(std::size_t a, const T& val)
    {
        value[a += half] = val;
        while (a >>= 1) { up(a); }
    }
    T accumulate(std::size_t L, std::size_t R) const
    {
        T accl = Monoid::id(), accr = Monoid::id();
        for (L += half, R += half; L < R; L >>= 1, R >>= 1) {
            if (L & 1) { accl = acc(accl, value[L++]); }
            if (R & 1) { accr = acc(value[--R], accr); }
        }
        return acc(accl, accr);
    }

private:
    void up(const std::size_t i) { value[i] = acc(value[i << 1], value[i << 1 | 1]); }
    const std::size_t data_num, half;
    std::vector<T> value;
    const Monoid acc{};
};
struct Max
{
    using T = ll;
    T operator()(const T& a, const T& b) const { return std::max(a, b); }
    static constexpr T id() { return -INF<T>; }
};

int main()
{
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    int N;
    std::cin >> N;
    std::set<ll> st;
    std::vector<Cake> cake(N);
    for (int i = 0; i < N; i++) { std::cin >> cake[i].A >> cake[i].B >> cake[i].C, st.insert(cake[i].A), st.insert(cake[i].B); }
    std::map<ll, int> zip;
    for (const ll e : st) {
        static int i = 1;
        zip[e] = i, i++;
    }
    for (int i = 0; i < N; i++) { cake[i].A = zip[cake[i].A], cake[i].B = zip[cake[i].B]; }
    std::sort(cake.begin(), cake.end());
    SegmentTree<Max> seg(2 * N + 1);
    seg.set(0, 0LL);
    for (int i = 0; i < N; i++) {
        if (i > 0 and cake[i].A <= cake[i - 1].A) { continue; }
        const ll B = cake[i].B, C = cake[i].C;
        const ll max = std::max(seg.get(B), seg.accumulate(0, B) + C);
        seg.set(B, max);
    }
    std::cout << seg.accumulate(0, 2 * N + 2) << std::endl;
    return 0;
}
0