結果

問題 No.777 再帰的ケーキ
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2019-01-02 16:32:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 436 ms / 2,000 ms
コード長 2,741 bytes
コンパイル時間 2,184 ms
コンパイル使用メモリ 186,616 KB
実行使用メモリ 32,216 KB
最終ジャッジ日時 2023-08-13 04:15:40
合計ジャッジ時間 8,832 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,100 KB
testcase_01 AC 3 ms
7,148 KB
testcase_02 AC 4 ms
7,104 KB
testcase_03 AC 3 ms
7,196 KB
testcase_04 AC 3 ms
7,036 KB
testcase_05 AC 4 ms
7,204 KB
testcase_06 AC 3 ms
7,096 KB
testcase_07 AC 4 ms
7,212 KB
testcase_08 AC 4 ms
7,192 KB
testcase_09 AC 4 ms
6,996 KB
testcase_10 AC 3 ms
7,204 KB
testcase_11 AC 3 ms
7,100 KB
testcase_12 AC 4 ms
7,160 KB
testcase_13 AC 3 ms
7,104 KB
testcase_14 AC 4 ms
7,032 KB
testcase_15 AC 3 ms
7,144 KB
testcase_16 AC 3 ms
7,284 KB
testcase_17 AC 3 ms
7,204 KB
testcase_18 AC 3 ms
7,088 KB
testcase_19 AC 4 ms
6,992 KB
testcase_20 AC 3 ms
7,152 KB
testcase_21 AC 6 ms
7,468 KB
testcase_22 AC 6 ms
7,436 KB
testcase_23 AC 4 ms
7,204 KB
testcase_24 AC 4 ms
7,040 KB
testcase_25 AC 6 ms
7,496 KB
testcase_26 AC 6 ms
7,412 KB
testcase_27 AC 4 ms
7,204 KB
testcase_28 AC 424 ms
32,184 KB
testcase_29 AC 420 ms
32,196 KB
testcase_30 AC 432 ms
32,204 KB
testcase_31 AC 436 ms
32,216 KB
testcase_32 AC 211 ms
32,156 KB
testcase_33 AC 68 ms
14,488 KB
testcase_34 AC 84 ms
15,728 KB
testcase_35 AC 297 ms
21,096 KB
testcase_36 AC 213 ms
32,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
#define def 0
template<class V, int NV> struct SegTree { //[l,r)
    V comp(V& l, V& r) { return max(l, r); };

    vector<V> val; SegTree() { val = vector<V>(NV * 2, def); }
    V get(int x, int y, int l = 0, int r = NV, int k = 1) {
        if (r <= x || y <= l)return def; if (x <= l && r <= y)return val[k];
        auto a = get(x, y, l, (l + r) / 2, k * 2); 
        auto b = get(x, y, (l + r) / 2, r, k * 2 + 1);
        return comp(a, b);
    }
    void update(int i, V v) {
        i += NV; val[i] = v;
        while (i>1) i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]);
    }
    void add(int i, V v) { update(i, val[i + NV] + v); }
    V operator[](int x) { return get(x, x + 1); }
};
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/





int N, A[201010], B[201010], C[201010];
SegTree<ll, 1 << 18> st;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> A[i] >> B[i] >> C[i];

    vector<int> v;
    rep(i, 0, N) v.push_back(B[i]);
    sort(all(v));
    v.erase(unique(all(v)), v.end());
    rep(i, 0, N) B[i] = lower_bound(all(v), B[i]) - v.begin();

    map<int, vector<int>> buf;
    rep(i, 0, N) buf[A[i]].push_back(i);

    fore(p, buf) {
        auto& v = p.second;
        vector<pair<int, ll>> nxt;
        fore(i, v) {
            ll c = st.get(0, B[i]) + C[i];
            nxt.push_back({ B[i], c });
        }
        fore(p, nxt) st.update(p.first, max(p.second, st[p.first]));
    }

    ll ans = st.get(0, N);
    cout << ans << endl;
}
0