結果

問題 No.777 再帰的ケーキ
ユーザー yumakmcyumakmc
提出日時 2019-03-18 21:58:04
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,062 bytes
コンパイル時間 2,781 ms
コンパイル使用メモリ 173,688 KB
実行使用メモリ 30,040 KB
最終ジャッジ日時 2023-09-26 10:42:01
合計ジャッジ時間 8,185 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,528 KB
testcase_01 AC 4 ms
7,180 KB
testcase_02 AC 4 ms
7,384 KB
testcase_03 WA -
testcase_04 AC 3 ms
7,312 KB
testcase_05 AC 4 ms
7,252 KB
testcase_06 AC 4 ms
7,244 KB
testcase_07 AC 4 ms
7,312 KB
testcase_08 AC 3 ms
7,248 KB
testcase_09 AC 3 ms
7,276 KB
testcase_10 AC 4 ms
7,328 KB
testcase_11 AC 4 ms
7,496 KB
testcase_12 AC 4 ms
7,380 KB
testcase_13 AC 4 ms
7,376 KB
testcase_14 AC 4 ms
7,228 KB
testcase_15 AC 4 ms
7,500 KB
testcase_16 AC 4 ms
7,180 KB
testcase_17 AC 3 ms
7,316 KB
testcase_18 WA -
testcase_19 AC 3 ms
7,388 KB
testcase_20 AC 4 ms
7,288 KB
testcase_21 AC 6 ms
7,596 KB
testcase_22 AC 6 ms
7,564 KB
testcase_23 AC 4 ms
7,360 KB
testcase_24 AC 4 ms
7,244 KB
testcase_25 AC 7 ms
7,560 KB
testcase_26 AC 6 ms
7,624 KB
testcase_27 AC 4 ms
7,256 KB
testcase_28 AC 603 ms
29,688 KB
testcase_29 AC 595 ms
29,736 KB
testcase_30 AC 610 ms
30,040 KB
testcase_31 AC 605 ms
29,804 KB
testcase_32 AC 382 ms
29,916 KB
testcase_33 AC 82 ms
9,836 KB
testcase_34 AC 122 ms
11,132 KB
testcase_35 AC 411 ms
20,316 KB
testcase_36 AC 380 ms
29,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;
#pragma warning(disable:4996)

#define Seg_Max_N (1<<18) 

using Value = long long int;
const Value ini =0;
struct segtree {
	int N;
	vector<Value>dat;

	segtree() {}
	segtree(int n) :dat(2 * Seg_Max_N) {
		N = 1;
		while (N < n) N *= 2;
		for (int i = 0; i < 2 * N - 1; i++) {
			dat[i] = ini;
		}
	}
	Value connect(const Value&l, const Value&r) {
		return max(l,r);
	}
	// update k th element
	void update(int k, Value a) {
		k += N - 1;
		dat[k] = a;

		while (k > 0) {
			k = (k - 1) / 2;
			const Value al(dat[k * 2 + 1]);
			const Value ar(dat[k * 2 + 2]);
			dat[k] = connect(al, ar);
		}
	}
	// min [a, b)
	Value  query(int a, int b) { return query(a, b, 0, 0, N); }
	Value  query(int a, int b, int k, int l, int r) {
		if (r <= a or b <= l) return ini;
		if (a <= l and r <= b) return dat[k];
		const int m = (l + r) / 2;
		const Value al(query(a, b, k * 2 + 1, l, m));
		const Value ar(query(a, b, k * 2 + 2, m, r));
		return connect(al, ar);
	}
};

struct cake {
	int a;
	int b;
	long long int c;
};
bool operator<(const cake&l, const cake&r) {
	return l.a<r.a;
}
template<typename T> struct Compress {
	map<T, int>mp;
	map<int, T>revmp;

	Compress(vector<T>vs) {
		setmp(vs);
	}

	Compress() :mp(), revmp() {

	}
	void setmp(vector<T>vs) {
		sort(vs.begin(), vs.end());
		vs.erase(unique(vs.begin(), vs.end()), vs.end());
		for (int i = 0; i < static_cast<int>(vs.size()); ++i) {
			mp[vs[i]] = i;
			revmp[i] = vs[i];
		}
	}

};

int main() {
	int N;cin>>N;
	vector<cake>cakes(N);
	vector<int>bs{ 0 };
	for (int i = 0; i < N; ++i) {
		int a,b;
		long long int c;
		scanf("%d %d %lld",&a,&b,&c);
		bs.push_back(b);
		cakes[i] = cake{ a,b,c };
	}
	Compress<int> cb(bs);
	sort(cakes.begin(),cakes.end());
	segtree seg(N+1);
	seg.update(0,0);
	for (int i = 0; i < N; ++i) {
		long long int num=seg.query(0,cb.mp[cakes[i].b]);
		seg.update(cb.mp[cakes[i].b],max(seg.query(cb.mp[cakes[i].b],cb.mp[cakes[i].b]+1),num+cakes[i].c));
	}
	long long int answer=seg.query(0,N+1);
	cout<<answer<<endl;
	return 0;
	
}
0