結果

問題 No.777 再帰的ケーキ
ユーザー face4face4
提出日時 2019-02-24 09:50:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 343 ms / 2,000 ms
コード長 1,769 bytes
コンパイル時間 1,012 ms
コンパイル使用メモリ 87,772 KB
実行使用メモリ 10,528 KB
最終ジャッジ日時 2023-08-22 21:10:38
合計ジャッジ時間 6,574 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 4 ms
4,380 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 4 ms
4,380 KB
testcase_26 AC 5 ms
4,376 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 302 ms
10,340 KB
testcase_29 AC 304 ms
10,524 KB
testcase_30 AC 343 ms
10,320 KB
testcase_31 AC 341 ms
10,528 KB
testcase_32 AC 251 ms
10,480 KB
testcase_33 AC 125 ms
6,892 KB
testcase_34 AC 186 ms
6,712 KB
testcase_35 AC 319 ms
8,836 KB
testcase_36 AC 247 ms
10,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

bool comp(pair<pii,int> a, pair<pii,int> b){
    if(a.first.first != b.first.first)  return a.first.first < b.first.first;
    if(a.first.second != b.first.second)    return a.first.second > b.first.second;
    return a.second < b.second;
}

struct ST{
private:
    int n;
    vector<ll> node;
public:
    ST(int siz){
        n = 1;
        while(n < siz)  n *= 2;
        node.resize(2*n-1, 0);
    }

    void assign(int i, ll x){
        i += n-1;
        if(node[i] >= x)    return;
        node[i] = x;
        while(i > 0){
            i = (i-1)/2;
            node[i] = max(node[2*i+1], node[2*i+2]);
        }
    }

    ll query(int a, int b, int k=0, int l=0, int r=-1){
        if(r < 0)   r = n;
        if(r <= a || b <= l)    return 0;
        if(a <= l && r <= b)    return node[k];
        ll lx = query(a, b, 2*k+1, l, (l+r)/2);
        ll rx = query(a, b, 2*k+2, (l+r)/2, r);
        return max(lx, rx);
    }
};

int main(){
    int n, a, b, c;
    vector<pair<pii, int>> v;
    vector<int> w;
    w.push_back(0), w.push_back(1000000001); // sentinel
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a >> b >> c;
        v.push_back({{a,b},c});
        w.push_back(b);
    }
    sort(w.begin(), w.end());
    w.erase(unique(w.begin(), w.end()), w.end());
    auto pos = [&](int val)->int{
        return lower_bound(w.begin(), w.end(), val)-w.begin();
    };
    sort(v.begin(), v.end(), comp);
    ST seg(w.size());
    for(int i = 0; i < n; i++){
        seg.assign(pos(v[i].first.second), seg.query(0, pos(v[i].first.second))+v[i].second);
    }

    cout << seg.query(0, w.size()) << endl;

    return 0;
}
0