結果

問題 No.777 再帰的ケーキ
ユーザー tottoripapertottoripaper
提出日時 2018-12-24 01:10:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,501 bytes
コンパイル時間 2,260 ms
コンパイル使用メモリ 185,440 KB
実行使用メモリ 12,056 KB
最終ジャッジ日時 2023-10-26 02:53:04
合計ジャッジ時間 5,434 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 WA -
testcase_07 WA -
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
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 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 3 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 2 ms
4,348 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 130 ms
11,968 KB
testcase_33 AC 68 ms
10,396 KB
testcase_34 AC 98 ms
11,968 KB
testcase_35 WA -
testcase_36 AC 127 ms
11,968 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;
    }
};

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(k, tmp[k]);
        }
    }

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