結果

問題 No.1826 Fruits Collecting
ユーザー pockynypockyny
提出日時 2022-01-28 22:50:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 6,105 bytes
コンパイル時間 3,256 ms
コンパイル使用メモリ 231,856 KB
実行使用メモリ 152,072 KB
最終ジャッジ日時 2023-08-28 21:25:47
合計ジャッジ時間 36,238 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,756 KB
testcase_01 AC 5 ms
6,148 KB
testcase_02 AC 6 ms
6,044 KB
testcase_03 AC 7 ms
6,108 KB
testcase_04 AC 3 ms
5,832 KB
testcase_05 AC 552 ms
67,356 KB
testcase_06 AC 1,038 ms
117,940 KB
testcase_07 WA -
testcase_08 AC 46 ms
12,540 KB
testcase_09 AC 932 ms
89,880 KB
testcase_10 AC 607 ms
71,440 KB
testcase_11 WA -
testcase_12 AC 203 ms
33,384 KB
testcase_13 AC 86 ms
18,772 KB
testcase_14 AC 143 ms
23,360 KB
testcase_15 WA -
testcase_16 AC 1,618 ms
151,908 KB
testcase_17 WA -
testcase_18 AC 1,612 ms
151,884 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 1,607 ms
151,812 KB
testcase_23 WA -
testcase_24 AC 1,607 ms
151,984 KB
testcase_25 AC 2 ms
5,492 KB
testcase_26 AC 2 ms
5,460 KB
testcase_27 AC 2 ms
5,384 KB
testcase_28 AC 2 ms
5,400 KB
testcase_29 AC 2 ms
5,428 KB
testcase_30 AC 190 ms
37,732 KB
testcase_31 AC 427 ms
70,608 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 232 ms
23,616 KB
testcase_36 WA -
testcase_37 AC 615 ms
80,428 KB
testcase_38 AC 429 ms
65,632 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 2 ms
5,552 KB
testcase_44 AC 2 ms
5,384 KB
testcase_45 AC 2 ms
5,408 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)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
typedef long long ll;
#define def 0
using V = ll;
V comp(V& l, V& r) { return max(l,r); };
struct SegTree { //[l,r)
    int NV;
    vector<V> val;
    void init(int n) {
        NV = 1;
        while (NV < n) NV *= 2;
        val = vector<V>(NV * 2, def);
    }
    V get(int x, int y, int l, int r, int k) {
        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);
    }
    V get(int x, int y) { return get(x, y, 0, NV, 1); }
    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); }
};

struct Healthy2DSegTree {
    int NV;
    vector<SegTree> st;
    vector<vector<int>> index;
    
    void init(vector<vector<int>> &v) {
        int n = v.size();
        NV = 1; while (NV < n) NV *= 2;
        index.resize(2 * NV);
        rep(i, 0, n) fore(j, v[i]) index[i + NV].push_back(j);
        rrep(i, NV * 2 - 1, 1) {
            sort(index[i].begin(), index[i].end());
            index[i].erase(unique(index[i].begin(), index[i].end()), index[i].end());
            fore(j, index[i]) index[i / 2].push_back(j);
        }
        st.resize(2 * NV);
        rep(i, 1, NV * 2) st[i].init(index[i].size());
    }
    void update(int x, int y, V v) {
        assert(x < NV);
        x += NV;
        while (x) {
            int yy = lower_bound(index[x].begin(), index[x].end(), y) - index[x].begin();
            assert(yy != index[x].size());
            assert(y == index[x][yy]);
            st[x].update(yy, v);
            x >>= 1;
        }
    }
    void add(int x, int y, V v) {
        assert(x < NV);
        x += NV;
        while (x) {
            int yy = lower_bound(index[x].begin(), index[x].end(), y) - index[x].begin();
            assert(yy != index[x].size());
            assert(y == index[x][yy]);
            st[x].add(yy, v);
            x >>= 1;
        }
    }
    V get(int sx, int tx, int sy, int ty, int k, int l, int r) {
        assert(k < NV * 2);
        assert(l < r);
        if (r <= sx or tx <= l) return def;
        if (sx <= l and r <= tx) {
            int syy = lower_bound(index[k].begin(), index[k].end(), sy) - index[k].begin();
            int tyy = lower_bound(index[k].begin(), index[k].end(), ty) - index[k].begin();
            return st[k].get(syy, tyy);
        }
        int md = (l + r) / 2;
        V le = get(sx, tx, sy, ty, k * 2, l, md);
        V ri = get(sx, tx, sy, ty, k * 2 + 1, md, r);
        return comp(le, ri);
    }
    V get(int sx, int tx, int sy, int ty) {
        return get(sx, tx, sy, ty, 1, 0, NV);
    }
};
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/



//int H, W, Q;
//vector<vector<int>> query;
//---------------------------------------------------------------------------------------------------
ll t[200010],x[200010],v[200010];
void _main(){
    int i,n; cin >> n;
    for(i=0;i<n;i++) cin >> t[i] >> x[i] >> v[i];
    vector<ll> a(n),b(n);
    for(i=0;i<n;i++){
        a[i] = t[i] + x[i]; b[i] = t[i] - x[i];
    }
    sort(a.begin(),a.end()); sort(b.begin(),b.end());
    vector<pair<ll,pair<ll,ll>>> w(n);
    vector<vector<int>> index(n);
    for(i=0;i<n;i++){
        w[i] = {t[i],{x[i],v[i]}};
        int xx = lower_bound(a.begin(),a.end(),t[i] + x[i]) - a.begin();
        int yy = lower_bound(b.begin(),b.end(),t[i] - x[i]) - b.begin();
        index[xx].push_back(yy);
    }
    sort(w.begin(),w.end());
    Healthy2DSegTree st;
    st.init(index);
    for(i=0;i<n;i++){
        if(w[i].first<abs(w[i].second.first)) continue;
        ll aa = w[i].first + w[i].second.first,bb = w[i].first - w[i].second.first;
        ll xx = lower_bound(a.begin(),a.end(),aa) - a.begin();
        ll yy = lower_bound(b.begin(),b.end(),bb) - b.begin();
        ll mx = st.get(0,xx + 1,0,yy + 1) + w[i].second.second;
        ll mx2 = st.get(xx,xx + 1,yy,yy + 1);
        if(mx2<=mx){
            st.add(xx,yy,-mx2);
            st.add(xx,yy,mx);
        }
    }
    cout << st.get(0,n,0,n) << endl;   
}

/*void _main() {
    cin >> H >> W >> Q;
    rep(i, 0, Q) {
        int t; cin >> t;
        if (t == 1) {
            int x, y, v; cin >> x >> y >> v;
            query.push_back({ t, x, y, v });
        }
        else {
            int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;
            query.push_back({ t, sx, sy, tx, ty });
        }
    }

    Healthy2DSegTree st;
    vector<vector<int>> index(W);
    rep(i, 0, Q) {
        if (query[i][0] == 1) {
            int x = query[i][1];
            int y = query[i][2];
            index[x].push_back(y);
        }
    }
    st.init(index);

    rep(i, 0, Q) {
        if (query[i][0] == 1) {
            int x = query[i][1];
            int y = query[i][2];
            int v = query[i][3];
            st.add(x, y, v);
        } else {
            int sx = query[i][1];
            int sy = query[i][2];
            int tx = query[i][3];
            int ty = query[i][4];
            ll ans = st.get(sx, tx + 1, sy, ty + 1);
            printf("%lld\n", ans);
        }
    }
}*/
0