結果

問題 No.777 再帰的ケーキ
ユーザー t98slider
提出日時 2023-08-09 04:47:14
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 171 ms / 2,000 ms
コード長 840 bytes
コンパイル時間 3,903 ms
コンパイル使用メモリ 242,068 KB
実行使用メモリ 12,068 KB
最終ジャッジ日時 2024-11-14 10:22:39
合計ジャッジ時間 6,622 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;

ll op(ll lhs, ll rhs){return max(lhs, rhs);}
ll e(){return 0;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, x, y, z;
    cin >> n;
    vector<tuple<int,int,int>> a(n);
    vector<int> cb(n);
    for(int i = 0; i < n; i++){
        cin >> x >> y >> z;
        a[i] = make_tuple(x, -y, z);
        cb[i] = y;
    }
    sort(cb.begin(), cb.end());
    cb.erase(unique(cb.begin(), cb.end()), cb.end());
    sort(a.begin(), a.end());
    atcoder::segtree<ll, op, e> seg(cb.size());
    for(int i = 0; i < n; i++){
        tie(x, y, z) = a[i];
        y = lower_bound(cb.begin(), cb.end(), -y) - cb.begin();
        ll v = seg.prod(0, y);
        seg.set(y, max(seg.get(y), v + z));
    }
    cout << seg.all_prod() << '\n';
}
0