結果

問題 No.3424 Shooting Game
コンテスト
ユーザー GOTKAKO
提出日時 2026-01-20 14:21:54
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 1,711 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,015 ms
コンパイル使用メモリ 219,480 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-01-20 14:21:58
合計ジャッジ時間 3,864 ms
ジャッジサーバーID
(参考情報)
judge3 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

using SS = int;
class DualSegmentTree{
    //作用させるものの交換法則が成り立つ時&&lazy->lazyとlazy->datの作用が同じ時専用.
    //出来ないときは遅延セグ木 出来たとしても改良必須あり.
    int siz,n;
    vector<SS> dat;
    void mapping(SS f,SS &x){x = max(x,f);}
    //FF composition(FF f, FF g){mappingと同じ?} チェック.
    SS e(){return 0;}
    public:
    DualSegmentTree(int N):n(N){
        n = N,siz = 1;
        while(siz < n) siz += siz;
        dat.resize(siz*2,e());
    }
    DualSegmentTree(vector<SS> &A){
        n = A.size(),siz = 1;
        while(siz < n) siz += siz;
        dat.resize(siz*2,e());
        for(int i=0; i<n; i++) dat.at(i+siz) = A.at(i);
    }
    void update(int pos,SS x){
        pos += siz;
        mapping(x,dat.at(pos));
    }
    void update(int l,int r,SS x){
        l += siz,r += siz;
        while(l < r){
            if(l&1) mapping(x,dat.at(l)),l++;
            if(r&1) r--,mapping(x,dat.at(r));
            l >>= 1; r >>= 1;
        }
    }
    SS get(int pos){
        pos = pos+siz;
        SS ret = dat.at(pos);
        while(pos != 1) pos = pos>>=1,mapping(dat.at(pos),ret);
        return ret;
    }
};

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N,T; cin >> N >> T;
    int n = 200001;
    vector<long long> dp(n+1);
    DualSegmentTree Z(n);
    while(N--){
        int l,r,p; cin >> l >> r >> p;
        Z.update(l,r+1,p);
    }
    for(int i=0; i<n; i++){
        dp.at(i+1) = max(dp.at(i),dp.at(i+1));
        dp.at(min(n,i+T)) = max(dp.at(min(n,i+T)),dp.at(i)+Z.get(i));
    }
    cout << dp.at(n) << endl;
}
0