結果

問題 No.1826 Fruits Collecting
ユーザー asaringoasaringo
提出日時 2022-01-31 22:02:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 344 ms / 2,000 ms
コード長 2,352 bytes
コンパイル時間 2,381 ms
コンパイル使用メモリ 196,124 KB
実行使用メモリ 19,744 KB
最終ジャッジ日時 2023-09-02 02:25:35
合計ジャッジ時間 11,902 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,440 KB
testcase_01 AC 5 ms
7,524 KB
testcase_02 AC 5 ms
7,520 KB
testcase_03 AC 6 ms
7,548 KB
testcase_04 AC 5 ms
7,476 KB
testcase_05 AC 130 ms
10,716 KB
testcase_06 AC 212 ms
13,000 KB
testcase_07 AC 150 ms
11,728 KB
testcase_08 AC 19 ms
7,848 KB
testcase_09 AC 211 ms
12,780 KB
testcase_10 AC 145 ms
11,488 KB
testcase_11 AC 139 ms
11,456 KB
testcase_12 AC 57 ms
8,672 KB
testcase_13 AC 29 ms
8,136 KB
testcase_14 AC 45 ms
8,528 KB
testcase_15 AC 334 ms
16,480 KB
testcase_16 AC 339 ms
16,612 KB
testcase_17 AC 337 ms
16,460 KB
testcase_18 AC 329 ms
16,444 KB
testcase_19 AC 331 ms
16,460 KB
testcase_20 AC 327 ms
16,952 KB
testcase_21 AC 334 ms
16,616 KB
testcase_22 AC 333 ms
16,300 KB
testcase_23 AC 338 ms
16,404 KB
testcase_24 AC 344 ms
16,580 KB
testcase_25 AC 4 ms
7,572 KB
testcase_26 AC 4 ms
7,600 KB
testcase_27 AC 3 ms
7,412 KB
testcase_28 AC 4 ms
7,476 KB
testcase_29 AC 4 ms
7,432 KB
testcase_30 AC 61 ms
8,572 KB
testcase_31 AC 119 ms
9,500 KB
testcase_32 AC 88 ms
11,508 KB
testcase_33 AC 319 ms
19,744 KB
testcase_34 AC 269 ms
17,504 KB
testcase_35 AC 57 ms
9,492 KB
testcase_36 AC 325 ms
19,116 KB
testcase_37 AC 199 ms
16,956 KB
testcase_38 AC 138 ms
13,796 KB
testcase_39 AC 223 ms
16,628 KB
testcase_40 AC 274 ms
18,808 KB
testcase_41 AC 61 ms
9,916 KB
testcase_42 AC 12 ms
7,688 KB
testcase_43 AC 4 ms
7,476 KB
testcase_44 AC 4 ms
7,472 KB
testcase_45 AC 3 ms
7,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef long double ld ;
typedef pair<ll,ll> P ;
typedef tuple<ll,ll,ll> TP ;
#define chmin(a,b) a = min(a,b)
#define chmax(a,b) a = max(a,b)
#define bit_count(x) __builtin_popcountll(x)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / gcd(a,b) * b
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define rrep(i,a,b) for(int i = a ; i < b ; i++)
#define endl "\n"

const int MAX_N = 1 << 18 ;

template<typename T>
struct SegmentTree{
    int n ;
    T dat[2 * MAX_N - 1] ;
    SegmentTree(int n_){
        n = 1 ;
        while(n < n_) n *= 2 ;
        memset(dat,0,sizeof(dat)) ;
    }
    void update(int k , T x){
        k += n - 1 ;
        dat[k] = x ;
        while(k > 0){
            k = (k - 1) / 2 ;
            dat[k] = max(dat[2*k+1],dat[2*k+2]) ;
        }
    }
    T sub_query(int a , int b , int k , int l , int r){
        if(r <= a || b <= l) return -1e18 ;
        if(a <= l && r <= b) return dat[k] ;
        T lef = sub_query(a,b,2*k+1,l,(l+r)/2) ;
        T rig = sub_query(a,b,2*k+2,(l+r)/2,r) ;
        return max(lef,rig) ;
    }
    T query(int a , int b){
        return sub_query(a,b,0,0,n) ;
    }
};

template<typename T> struct Compress{
    vector<int> vec ;
    unordered_map<T,ll> mp ;
    Compress(vector<T> A){
        int n = A.size() ;
        vector<int> B(n) ;
        for(int i = 0 ; i < n ; i++) B[i] = A[i] ;
        vec.resize(n) ;
        sort(A.begin(),A.end()) ;
        for(int i = 0 ; i < n ; i++){
            auto it = lower_bound(A.begin(),A.end(),B[i]) ;
            vec[i] = it - A.begin() ;
            mp[B[i]] = it - A.begin();
        }
    }
    inline int compress(ll i) { return mp[i] ; }
    inline int operator [] (int i) { return vec[i] ; }
};

int n ;
vector<TP> X ;
vector<ll> vec ;

int main(){
    cin >> n ;
    rep(i,n){
        ll t , x , v ;
        cin >> t >> x >> v ;
        if(abs(x)>t) continue ;
        X.push_back({x+t,t-x,v}) ;
        vec.push_back(t-x) ;
    }
    sort(X.begin(),X.end()) ;
    Compress<ll> s(vec) ;
    SegmentTree<ll> segtree(n) ;
    for(int i = X.size() - 1 ; i >= 0 ; i--){
        ll x , y , v ;
        tie(x,y,v) = X[i] ;
        ll k = s.compress(y) ;
        ll val = segtree.query(k,n) ;
        segtree.update(k,val+v) ;
    }
    cout << segtree.query(0,n) << endl ;
}
0