結果

問題 No.1826 Fruits Collecting
ユーザー 👑 NachiaNachia
提出日時 2022-01-28 21:40:55
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 2,943 bytes
コンパイル時間 3,532 ms
コンパイル使用メモリ 93,064 KB
実行使用メモリ 19,308 KB
最終ジャッジ日時 2023-08-28 19:29:17
合計ジャッジ時間 6,576 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 61 ms
9,912 KB
testcase_06 AC 99 ms
16,260 KB
testcase_07 AC 70 ms
10,808 KB
testcase_08 AC 8 ms
4,380 KB
testcase_09 AC 94 ms
12,632 KB
testcase_10 AC 66 ms
10,356 KB
testcase_11 AC 63 ms
10,356 KB
testcase_12 AC 26 ms
6,264 KB
testcase_13 AC 13 ms
4,792 KB
testcase_14 AC 20 ms
5,316 KB
testcase_15 AC 147 ms
18,928 KB
testcase_16 AC 149 ms
19,276 KB
testcase_17 AC 147 ms
19,156 KB
testcase_18 AC 145 ms
19,116 KB
testcase_19 AC 144 ms
19,260 KB
testcase_20 AC 149 ms
19,084 KB
testcase_21 AC 149 ms
19,204 KB
testcase_22 AC 146 ms
19,116 KB
testcase_23 AC 148 ms
19,308 KB
testcase_24 AC 148 ms
19,092 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 31 ms
6,668 KB
testcase_31 AC 60 ms
10,028 KB
testcase_32 AC 35 ms
6,728 KB
testcase_33 AC 115 ms
17,076 KB
testcase_34 AC 96 ms
12,100 KB
testcase_35 AC 23 ms
5,188 KB
testcase_36 AC 112 ms
16,344 KB
testcase_37 AC 79 ms
11,660 KB
testcase_38 AC 56 ms
10,144 KB
testcase_39 AC 82 ms
15,888 KB
testcase_40 AC 105 ms
17,664 KB
testcase_41 AC 23 ms
6,300 KB
testcase_42 AC 5 ms
4,380 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #




#include <vector>
#include <algorithm>

namespace nachia{

class CoordinateCompress {
    using Elem = long long;
    static const Elem negInf = -1001001001001001001;
    std::vector<std::pair<Elem, int>> G;
    std::vector<int> res;
    std::vector<Elem> mRealval;
    Elem mMaxcoord;
    bool ok = true;
    void calc() {
        if (ok) return;
        sort(G.begin(), G.end());
        res.resize(G.size());
        mRealval.clear();
        Elem x = negInf;
        int p = -1;
        for(int i=0; i<(int)G.size(); i++){
            if (x != G[i].first) { x = G[i].first; mRealval.push_back(x); p++; }
            res[G[i].second] = p;
        }
        mMaxcoord = p;
        ok = true;
    }
public:
    int push(Elem x) {
        ok = false;
        G.push_back({ x,(int)G.size() });
        return G.back().second;
    }
    int operator[](int i) {
        calc();
        return res[i];
    }
    Elem realval(int x) {
        calc();
        return mRealval[x];
    }
    Elem maxcoord() {
        calc();
        return mMaxcoord;
    }
};

template<class Elem>
std::vector<int> coordinate_compress_instant(const std::vector<Elem>& A, bool disjoint = false){
    int n = A.size();
    std::vector<int> ord(n);
    for(int i=0; i<n; i++) ord[i] = i;
    if(disjoint){
        std::sort(ord.begin(), ord.end(), [&](int l, int r) -> bool { return (A[l] != A[r]) ? (A[l] < A[r]) : (l < r); });
        std::vector<int> res(n, 0);
        for(int i=0; i<n; i++) res[ord[i]] = i;
        return res;
    }
    std::sort(ord.begin(), ord.end(), [&](int l, int r) -> bool { return A[l] < A[r]; });
    std::vector<int> res(n, 0);
    for(int i=1; i<n; i++) res[ord[i]] = res[ord[i-1]] + ((A[ord[i-1]] < A[ord[i]]) ? 1 : 0);
    return res;
}

}

#include <iostream>
#include <vector>
#include <algorithm>
#include <atcoder/segtree>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
using i32 = int;
using u32 = unsigned int;
#define rep(i,n) for(int i=0; i<(n); i++)



namespace RQ{
    using S = i64;
    S op(S l, S r){ return max(l,r); }
    S e(){ return 0; }
    using RQ = atcoder::segtree<S,op,e>;
}


struct Item{ i64 x,y,v; };
bool sortItem(Item l, Item r){ return make_pair(l.x, l.y) < make_pair(r.x,r.y); }
nachia::CoordinateCompress CCY;

int main() {
    int N; cin >> N;
    vector<Item> A(N);
    rep(i,N){
        i64 x,y,v; cin >> x >> y >> v;
        A[i] = { x+y, x-y, v };
        if(x+y < 0 || x-y < 0) A[i] = {0,0,0};
    }

    rep(i,N) A[i].y = CCY.push(A[i].y);
    rep(i,N) A[i].y = CCY[A[i].y];
    sort(A.begin(), A.end(), sortItem);

    RQ::RQ rq(N);
    for(auto [x,y,v] : A){
        i64 pans = rq.prod(0,y+1);
        rq.set(y, pans + v);
    }

    i64 ans = rq.all_prod();
    cout << ans << "\n";

    return 0;
}



struct ios_do_not_sync{
    ios_do_not_sync(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }
} ios_do_not_sync_instance;
0