結果

問題 No.777 再帰的ケーキ
ユーザー tottoripapertottoripaper
提出日時 2018-12-24 01:16:14
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 218 ms / 2,000 ms
コード長 2,606 bytes
コンパイル時間 2,396 ms
コンパイル使用メモリ 185,448 KB
実行使用メモリ 12,016 KB
最終ジャッジ日時 2023-10-26 02:53:10
合計ジャッジ時間 4,980 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 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 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 4 ms
4,348 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 3 ms
4,348 KB
testcase_25 AC 4 ms
4,348 KB
testcase_26 AC 4 ms
4,348 KB
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 200 ms
12,016 KB
testcase_29 AC 204 ms
12,016 KB
testcase_30 AC 215 ms
12,016 KB
testcase_31 AC 218 ms
12,016 KB
testcase_32 AC 122 ms
12,016 KB
testcase_33 AC 68 ms
10,444 KB
testcase_34 AC 97 ms
12,016 KB
testcase_35 AC 196 ms
12,016 KB
testcase_36 AC 121 ms
12,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

struct SegmentTree{
    int numLeaf;
    std::vector<ll> data;
    
    SegmentTree(int n){
        numLeaf = 1;
        while(numLeaf < n){
            numLeaf *= 2;
        }

        data.assign(numLeaf * 2, 0);
    }

    void set(int k, ll v){
        k += numLeaf;
        data[k] = v;

        while(k > 1){
            k /= 2;
            data[k] = std::max(data[k*2], data[k*2+1]);
        }
    }

    ll max(int l, int r){
        l += numLeaf;
        r += numLeaf;

        ll res = 0;
        for(;l<r;l/=2,r/=2){
            if(l & 1){
                res = std::max(res, data[l]);
                l += 1;
            }
            if(r & 1){
                r -= 1;
                res = std::max(res, data[r]);
            }
        }

        return res;
    }

    inline ll at(int k){
        return data[k + numLeaf];
    }
};

int N;
std::vector<P> ps;
ll tmp[200100];

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> N;

    ps.resize(N);
    for(int i=0;i<N;++i){
        std::cin >> fst(ps[i]) >> snd(ps[i]) >> thd(ps[i]);
    }

    // 座標圧縮
    {
        std::vector<int> v(N);
        for(int i=0;i<N;++i){
            v[i] = fst(ps[i]);
        }

        std::sort(v.begin(), v.end());
        v.erase(std::unique(v.begin(), v.end()), v.end());

        for(int i=0;i<N;++i){
            fst(ps[i]) = std::lower_bound(v.begin(), v.end(), fst(ps[i])) - v.begin();
        }
    }

    {
        std::vector<int> v(N);
        for(int i=0;i<N;++i){
            v[i] = snd(ps[i]);
        }

        std::sort(v.begin(), v.end());
        v.erase(std::unique(v.begin(), v.end()), v.end());

        for(int i=0;i<N;++i){
            snd(ps[i]) = std::lower_bound(v.begin(), v.end(), snd(ps[i])) - v.begin();
        }
    }

    std::sort(ps.begin(), ps.end());

    SegmentTree seg(N);
    for(int i=0,j=0;i<N;i=j){
        while(j < N && fst(ps[j]) == fst(ps[i])){
            j += 1;
        }
        
        for(int k=i;k<j;++k){
            tmp[k] = seg.max(0, snd(ps[k])) + thd(ps[k]);
        }

        for(int k=i;k<j;++k){
            seg.set(snd(ps[k]), std::max(seg.at(snd(ps[k])), tmp[k]));
        }
    }

    ll res = seg.max(0, N);
    std::cout << res << std::endl;
}
0