結果

問題 No.844 split game
ユーザー mamekinmamekin
提出日時 2019-06-28 21:48:45
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 163 ms / 2,000 ms
コード長 3,336 bytes
コンパイル時間 1,382 ms
コンパイル使用メモリ 127,936 KB
実行使用メモリ 6,900 KB
最終ジャッジ日時 2023-09-14 21:51:10
合計ジャッジ時間 7,061 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
4,640 KB
testcase_01 AC 49 ms
5,844 KB
testcase_02 AC 129 ms
5,448 KB
testcase_03 AC 95 ms
5,932 KB
testcase_04 AC 48 ms
4,764 KB
testcase_05 AC 144 ms
6,452 KB
testcase_06 AC 44 ms
4,456 KB
testcase_07 AC 35 ms
5,548 KB
testcase_08 AC 22 ms
4,376 KB
testcase_09 AC 106 ms
4,460 KB
testcase_10 AC 152 ms
5,692 KB
testcase_11 AC 146 ms
6,488 KB
testcase_12 AC 102 ms
4,396 KB
testcase_13 AC 63 ms
4,376 KB
testcase_14 AC 65 ms
4,760 KB
testcase_15 AC 163 ms
6,756 KB
testcase_16 AC 160 ms
6,724 KB
testcase_17 AC 160 ms
6,792 KB
testcase_18 AC 160 ms
6,900 KB
testcase_19 AC 161 ms
6,760 KB
testcase_20 AC 161 ms
6,700 KB
testcase_21 AC 159 ms
6,872 KB
testcase_22 AC 161 ms
6,696 KB
testcase_23 AC 5 ms
4,376 KB
testcase_24 AC 12 ms
4,376 KB
testcase_25 AC 7 ms
4,376 KB
testcase_26 AC 4 ms
4,380 KB
testcase_27 AC 10 ms
4,376 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 10 ms
4,376 KB
testcase_30 AC 12 ms
4,380 KB
testcase_31 AC 10 ms
4,376 KB
testcase_32 AC 3 ms
4,380 KB
testcase_33 AC 13 ms
4,376 KB
testcase_34 AC 8 ms
4,376 KB
testcase_35 AC 16 ms
4,376 KB
testcase_36 AC 9 ms
4,380 KB
testcase_37 AC 22 ms
4,376 KB
testcase_38 AC 45 ms
4,376 KB
testcase_39 AC 96 ms
4,924 KB
testcase_40 AC 29 ms
4,380 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 1 ms
4,376 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 1 ms
4,376 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 2 ms
4,380 KB
testcase_53 AC 1 ms
4,380 KB
testcase_54 AC 1 ms
4,376 KB
testcase_55 AC 2 ms
4,380 KB
testcase_56 AC 1 ms
4,376 KB
testcase_57 AC 1 ms
4,380 KB
testcase_58 AC 2 ms
4,380 KB
testcase_59 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

class SegmentTree
{
public:
    typedef long long T1;
    typedef long long T2;

    // データの初期値、以下の条件を満たすこと
    //   uniteData(v, INIT_DATA) == v
    static const T1 INIT_DATA;

    // 2つの区間の計算結果v1,v2に対して、
    // その2つの区間を統合した区間における計算結果を返す
    static T1 uniteData(T1 v1, T1 v2){
        return max(v1, v2);
    }

private:
    // 前回の値がprevである要素に対して、
    // パラメータxを用いた更新処理を適用した後の計算結果を返す
    T1 updateData(T1 prev, T2 x){
        return max(prev, x);
    }

    int n;
    vector<T1> data;
    void updateTree(int a, int k, int l, int r, T2 x){
        if(r - l == 1 && a == l){
            data[k] = updateData(data[k], x);
        }
        else if(l <= a && a < r){
            updateTree(a, k*2+1, l, (l+r+1)/2, x);
            updateTree(a, k*2+2, (l+r+1)/2, r, x);
            data[k] = uniteData(data[k*2+1], data[k*2+2]);
        }
    }
    T1 getValue(int a, int b, int k, int l, int r){
        if(a <= l && r <= b){
            return data[k];
        }
        else if(a < r && l < b){
            T1 v1 = getValue(a, b, k*2+1, l, (l+r+1)/2);
            T1 v2 = getValue(a, b, k*2+2, (l+r+1)/2, r);
            return uniteData(v1, v2);
        }
        else{
            return INIT_DATA;
        }
    }

public:
    SegmentTree(int n0){
        n = 1;
        while(n < n0)
            n *= 2;
        data.assign(2*n-1, INIT_DATA);
    }
    SegmentTree(const vector<T1>& v) : SegmentTree((int)v.size()){
        for(unsigned i=0; i<v.size(); ++i)
            data[n-1+i] = v[i];
        for(int k=n-2; k>=0; --k)
            data[k] = uniteData(data[k*2+1], data[k*2+2]);
    }
    // a番目の要素にパラメータxによる更新処理を適用
    void update(int a, T2 x){
        updateTree(a, 0, 0, n, x);
    }
    // 区間[a,b)の計算結果を返す
    T1 get(int a, int b){
        return getValue(a, b, 0, 0, n);
    }
};
const SegmentTree::T1 SegmentTree::INIT_DATA = LLONG_MIN / 2;

class Data
{
public:
    int l, r;
    long long p;
    bool operator<(const Data& other) const{
        return l < other.l;
    }
};

int main()
{
    int n, m;
    long long a;
    cin >> n >> m >> a;
    vector<Data> v(m);
    for(int i=0; i<m; ++i){
        cin >> v[i].l >> v[i].r >> v[i].p;
        -- v[i].l;
    }
    sort(v.begin(), v.end());

    SegmentTree st(n+1);
    st.update(0, 0);
    for(int i=0; i<m; ++i){
        long long x = st.get(0, v[i].l);
        st.update(v[i].r, x - 2 * a + v[i].p);
        long long y = st.get(v[i].l, v[i].l + 1);
        st.update(v[i].r, y - a + v[i].p);
    }

    long long ans = max(st.get(0, n), st.get(n, n+1) + a);
    cout << ans << endl;

    return 0;
}
0