結果

問題 No.1826 Fruits Collecting
ユーザー IKyoproIKyopro
提出日時 2020-11-01 16:43:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 154 ms / 2,000 ms
コード長 2,807 bytes
コンパイル時間 4,280 ms
コンパイル使用メモリ 214,328 KB
実行使用メモリ 18,264 KB
最終ジャッジ日時 2023-08-28 18:19:01
合計ジャッジ時間 10,390 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 2 ms
4,508 KB
testcase_05 AC 56 ms
7,376 KB
testcase_06 AC 93 ms
10,720 KB
testcase_07 AC 65 ms
8,004 KB
testcase_08 AC 8 ms
4,376 KB
testcase_09 AC 90 ms
9,404 KB
testcase_10 AC 61 ms
7,712 KB
testcase_11 AC 58 ms
7,716 KB
testcase_12 AC 24 ms
5,188 KB
testcase_13 AC 12 ms
4,376 KB
testcase_14 AC 20 ms
4,556 KB
testcase_15 AC 141 ms
13,248 KB
testcase_16 AC 140 ms
13,356 KB
testcase_17 AC 142 ms
13,280 KB
testcase_18 AC 141 ms
13,384 KB
testcase_19 AC 141 ms
13,300 KB
testcase_20 AC 141 ms
13,260 KB
testcase_21 AC 143 ms
13,460 KB
testcase_22 AC 141 ms
13,360 KB
testcase_23 AC 142 ms
13,388 KB
testcase_24 AC 141 ms
13,384 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,384 KB
testcase_30 AC 25 ms
4,684 KB
testcase_31 AC 46 ms
5,880 KB
testcase_32 AC 44 ms
7,740 KB
testcase_33 AC 154 ms
18,264 KB
testcase_34 AC 126 ms
14,828 KB
testcase_35 AC 29 ms
5,948 KB
testcase_36 AC 151 ms
18,132 KB
testcase_37 AC 96 ms
14,072 KB
testcase_38 AC 67 ms
11,384 KB
testcase_39 AC 107 ms
12,428 KB
testcase_40 AC 137 ms
14,376 KB
testcase_41 AC 30 ms
5,828 KB
testcase_42 AC 5 ms
4,380 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;}
#define all(x) (x).begin(),(x).end()
#define debug(x)  cerr << #x << " = " << (x) << endl;

template<typename Monoid,typename F>
class SegmentTree{
private:
    int sz;
    vector<Monoid> seg;
    const F op;
    const Monoid e;
public:
    SegmentTree(int n,const F op,const Monoid &e):op(op),e(e){
        sz = 1;
        while(sz<=n) sz <<= 1;
        seg.assign(2*sz,e);
    }
    void set(int k, const Monoid &x){
        seg[k+sz] = x;
    }
    void build(){
        for(int i=sz-1;i>0;i--){
            seg[i] = op(seg[2*i],seg[2*i+1]);
        }
    }
    void update(int k,const Monoid &x){
        k += sz;
        seg[k] = x;
        while(k>>=1){
            seg[k] = op(seg[2*k],seg[2*k+1]);
        }
    }
    Monoid query(int l,int r){
        Monoid L = e,R = e;
        for(l+=sz,r+=sz;l<r;l>>=1,r>>=1){
            if(l&1) L = op(L,seg[l++]);
            if(r&1) R = op(seg[--r],R);
        }
        return op(L,R);
    }
    Monoid operator[](const int &k)const{
        return seg[k+sz];
    }
};

template<class T>
class Compress {
    int N;
    map<int,T> value;
    vec<T> v;
    vec<T> cmp;
public:
    Compress(){}
    void add(T x){v.push_back(x);}
    void build(){
        for(auto &x:v) cmp.push_back(x);
        sort(cmp.begin(),cmp.end());
        cmp.erase(unique(cmp.begin(),cmp.end()),cmp.end());
        N = cmp.size();
    }
    int id(T val) {return lower_bound(cmp.begin(),cmp.end(),val)-cmp.begin();}
    T val(int id) {return cmp[id];}
    int size(){return N;}
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<int> X,Y,V;
    Compress<int> cx,cy;
    for(int i=0;i<N;i++){
        int t,x,v;
        cin >> t >> x >> v;
        if(t+x>=0 && t-x>=0){
            X.push_back(t+x);
            Y.push_back(t-x);
            V.push_back(v);
            cx.add(t+x);
            cy.add(t-x);
        }
    }
    N = X.size();
    cx.add(0),cy.add(0);
    cx.build(); cy.build();
    int A = cx.size(),B = cy.size();
    vvec<int> list(A);
    for(int i=0;i<N;i++){
        list[cx.id(X[i])].push_back(i);
    }
    ll inf = 1e18;
    SegmentTree seg(B,[](ll a,ll b){return max(a,b);},-inf);
    seg.set(cy.id(0),0);
    seg.build();
    for(int x=0;x<A;x++){
        sort(all(list[x]),[&](int i,int j){return Y[i]<Y[j];});
        for(auto& id:list[x]){
            int y = cy.id(Y[id]);
            seg.update(y,seg.query(0,y+1)+V[id]);
        }
    }
    cout << seg.query(0,B) << "\n";
}
0