結果

問題 No.844 split game
ユーザー treeonetreeone
提出日時 2019-06-28 22:36:27
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 2,106 bytes
コンパイル時間 2,390 ms
コンパイル使用メモリ 212,740 KB
実行使用メモリ 7,572 KB
最終ジャッジ日時 2023-09-14 22:20:32
合計ジャッジ時間 6,117 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
5,152 KB
testcase_01 AC 22 ms
5,636 KB
testcase_02 AC 54 ms
6,140 KB
testcase_03 AC 40 ms
6,544 KB
testcase_04 AC 21 ms
4,836 KB
testcase_05 AC 60 ms
7,216 KB
testcase_06 AC 19 ms
4,568 KB
testcase_07 AC 16 ms
5,636 KB
testcase_08 AC 9 ms
4,376 KB
testcase_09 AC 43 ms
5,212 KB
testcase_10 AC 60 ms
6,364 KB
testcase_11 AC 60 ms
7,252 KB
testcase_12 AC 42 ms
5,160 KB
testcase_13 AC 26 ms
4,440 KB
testcase_14 AC 26 ms
4,836 KB
testcase_15 AC 65 ms
7,480 KB
testcase_16 AC 65 ms
7,460 KB
testcase_17 AC 64 ms
7,488 KB
testcase_18 AC 66 ms
7,456 KB
testcase_19 AC 64 ms
7,448 KB
testcase_20 AC 66 ms
7,476 KB
testcase_21 AC 65 ms
7,460 KB
testcase_22 AC 65 ms
7,572 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 6 ms
4,376 KB
testcase_25 AC 4 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 5 ms
4,376 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 5 ms
4,380 KB
testcase_30 AC 6 ms
4,380 KB
testcase_31 AC 5 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 7 ms
4,376 KB
testcase_34 AC 4 ms
4,376 KB
testcase_35 AC 8 ms
4,376 KB
testcase_36 AC 5 ms
4,376 KB
testcase_37 AC 11 ms
4,380 KB
testcase_38 AC 18 ms
4,376 KB
testcase_39 AC 38 ms
5,756 KB
testcase_40 AC 13 ms
4,564 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 2 ms
4,384 KB
testcase_49 AC 2 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,376 KB
testcase_56 AC 2 ms
4,376 KB
testcase_57 AC 2 ms
4,380 KB
testcase_58 AC 1 ms
4,380 KB
testcase_59 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

struct S{
    int l, r, p;
    bool operator<(const S &s) const{
        if(l == s.l) return r < s.r;
        return l < s.l;
    }
};

template< typename T, typename E >
struct SegmentTree{
	using F = function< T(T, T) >;
	using G = function< T(T, E) >;
	int sz;
	vector<T> dat;
	F f;
	G g;
	T t1;
	SegmentTree(int n, F f, G g, T t1) : f(f), g(g), t1(t1) {
		sz = 1;
		while(sz < n) sz *= 2;
		dat.clear();
		dat.resize(2 * sz - 1, t1);
	}
	void set(int k, T x) { dat[k + sz - 1] = x; }
	void build() {
		for(int k = sz - 2; k >= 0; k--) {
			dat[k] = f(dat[2 * k + 1], dat[2 * k + 2]);
		}
	}
	void update(int k, E x) {
		k += sz - 1;
		dat[k] = g(dat[k], x);
		while(k > 0) {
			k = (k - 1) / 2;
			dat[k] = f(dat[2 * k + 1], dat[2 * k + 2]);
		}
	}
	T query(int a, int b, int k, int l, int r) {
		if(r <= a || b <= l) return t1;
		if(a <= l && r <= b) return dat[k];
		T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
		T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
		return f(vl, vr);
	}
	T query(int a, int b){ return query(a, b, 0, 0, sz); }
	T operator[](int k) { return dat[k + sz - 1]; }
};

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m, a;
    cin >> n >> m >> a;
    vector<S> d(m);
    SegmentTree<int, int> rmq(n + 1, 
		[](int a, int b){ return max(a, b); }, 
		[](int a, int b){ return max(a, b); }, 
		-INF);
    rep(i, 0, m){
        cin >> d[i].l >> d[i].r >> d[i].p;
        d[i].l--;
    }
    rmq.update(0, 0);
    sort(d.begin(), d.end());
    for(int i = 0; i < m; i++){
        int tmp = rmq[d[i].l] - a;
        // cout << i << ' ' << tmp << endl;
        tmp = max(tmp, rmq.query(0, d[i].l) - 2 * a);
        if(d[i].r == n) tmp += a;
        rmq.update(d[i].r, tmp + d[i].p);
        // rep(j, 0, n + 1){
        //     cout << rmq[j] << " ";
        // }
        // cout << endl;
    }
    int ans = rmq.query(0, n + 1);
    cout << ans << endl;
}
0