結果

問題 No.2808 Concentration
ユーザー rniyarniya
提出日時 2024-07-12 22:22:51
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,996 ms / 2,000 ms
コード長 2,604 bytes
コンパイル時間 4,068 ms
コンパイル使用メモリ 277,144 KB
実行使用メモリ 274,364 KB
最終ジャッジ日時 2024-07-12 22:24:50
合計ジャッジ時間 76,362 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,938 ms
274,176 KB
testcase_01 AC 1,845 ms
274,164 KB
testcase_02 AC 1,996 ms
274,304 KB
testcase_03 AC 1,817 ms
274,172 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 738 ms
122,324 KB
testcase_08 AC 291 ms
56,320 KB
testcase_09 AC 10 ms
5,376 KB
testcase_10 AC 1,150 ms
214,264 KB
testcase_11 AC 1,154 ms
207,376 KB
testcase_12 AC 528 ms
99,392 KB
testcase_13 AC 1,714 ms
260,988 KB
testcase_14 AC 246 ms
52,836 KB
testcase_15 AC 1,576 ms
254,176 KB
testcase_16 AC 1,642 ms
249,136 KB
testcase_17 AC 1,857 ms
266,160 KB
testcase_18 AC 1,802 ms
273,988 KB
testcase_19 AC 895 ms
135,204 KB
testcase_20 AC 1,650 ms
265,072 KB
testcase_21 AC 1,514 ms
244,216 KB
testcase_22 AC 1,137 ms
204,132 KB
testcase_23 AC 1,006 ms
198,848 KB
testcase_24 AC 1,641 ms
256,416 KB
testcase_25 AC 882 ms
136,008 KB
testcase_26 AC 1,718 ms
254,192 KB
testcase_27 AC 1,910 ms
274,076 KB
testcase_28 AC 1,829 ms
274,220 KB
testcase_29 AC 1,817 ms
274,232 KB
testcase_30 AC 1,820 ms
274,064 KB
testcase_31 AC 1,740 ms
274,140 KB
testcase_32 AC 1,754 ms
274,248 KB
testcase_33 AC 1,852 ms
274,096 KB
testcase_34 AC 1,776 ms
274,236 KB
testcase_35 AC 1,743 ms
274,248 KB
testcase_36 AC 1,851 ms
274,236 KB
testcase_37 AC 1,874 ms
274,220 KB
testcase_38 AC 1,868 ms
274,228 KB
testcase_39 AC 1,781 ms
274,364 KB
testcase_40 AC 1,813 ms
274,196 KB
testcase_41 AC 1,813 ms
274,232 KB
testcase_42 AC 1,898 ms
274,348 KB
testcase_43 AC 1,879 ms
274,216 KB
testcase_44 AC 1,811 ms
274,224 KB
testcase_45 AC 1,780 ms
274,060 KB
testcase_46 AC 1,803 ms
274,008 KB
testcase_47 AC 2 ms
5,376 KB
testcase_48 AC 2 ms
5,376 KB
testcase_49 AC 2 ms
5,376 KB
testcase_50 AC 2 ms
5,376 KB
testcase_51 AC 2 ms
5,376 KB
testcase_52 AC 2 ms
5,376 KB
testcase_53 AC 2 ms
5,376 KB
testcase_54 AC 2 ms
5,376 KB
testcase_55 AC 2 ms
5,376 KB
testcase_56 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void(0)
#endif

template <class T> std::istream& operator>>(std::istream& is, std::vector<T>& v) {
    for (auto& e : v) {
        is >> e;
    }
    return is;
}

template <class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
    for (std::string_view sep = ""; const auto& e : v) {
        os << std::exchange(sep, " ") << e;
    }
    return os;
}

template <class T, class U = T> bool chmin(T& x, U&& y) {
    return y < x and (x = std::forward<U>(y), true);
}

template <class T, class U = T> bool chmax(T& x, U&& y) {
    return x < y and (x = std::forward<U>(y), true);
}

template <class T> void mkuni(std::vector<T>& v) {
    std::ranges::sort(v);
    auto result = std::ranges::unique(v);
    v.erase(result.begin(), result.end());
}

template <class T> int lwb(const std::vector<T>& v, const T& x) {
    return std::distance(v.begin(), std::ranges::lower_bound(v, x));
}

#include <atcoder/lazysegtree>

using ll = long long;

using namespace std;

const int INF = 1 << 30;
const ll IINF = 1LL << 60;

ll op(ll l, ll r) { return max(l, r); }

ll e() { return -IINF; }

ll mapping(ll l, ll r) { return l + r; }

ll composition(ll l, ll r) { return l + r; }

ll id() { return 0; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    int N, S, H;
    cin >> N >> S >> H;
    vector<int> X(N), Y(N), Z(N);
    for (int i = 0; i < N; i++) cin >> X[i] >> Y[i] >> Z[i];

    vector<int> cand;
    cand.emplace_back(-INF);
    for (int i = 0; i < N; i++) {
        for (int d : {-H, -S, 0, S, H}) {
            cand.emplace_back(X[i] + d);
            cand.emplace_back(Y[i] + d);
        }
    }
    mkuni(cand);
    int len = cand.size();
    map<int, int> mp;
    for (int i = 0; i < len; i++) mp[cand[i]] = i;
    vector<vector<int>> End(len);
    for (int i = 0; i < N; i++) {
        if (Y[i] - X[i] > S) continue;
        End[mp[Y[i]]].emplace_back(i);
    }
    atcoder::lazy_segtree<ll, op, e, ll, mapping, composition, id> seg1(len), seg2(len);
    seg1.set(0, 0);
    seg2.set(0, 0);
    for (int i = 1, p = 0, q = 0; i < len; i++) {
        while (p < len and cand[p] < cand[i] - S) p++;
        while (q < len and cand[q] <= cand[i] - H) q++;
        for (int& idx : End[i]) {
            seg2.apply(p, mp[X[idx]] + 1, Z[idx]);
            seg1.set(i, seg2.prod(p, i));
        }
        seg2.set(i, seg1.prod(0, q));
    }

    ll ans = max(seg1.all_prod(), seg2.all_prod());
    cout << ans << "\n";
    return 0;
}
0