結果

問題 No.777 再帰的ケーキ
ユーザー leaf_1415leaf_1415
提出日時 2019-01-11 04:22:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 207 ms / 2,000 ms
コード長 1,797 bytes
コンパイル時間 850 ms
コンパイル使用メモリ 77,992 KB
実行使用メモリ 21,336 KB
最終ジャッジ日時 2024-05-04 03:48:50
合計ジャッジ時間 3,961 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,296 KB
testcase_01 AC 4 ms
7,296 KB
testcase_02 AC 4 ms
7,296 KB
testcase_03 AC 3 ms
7,168 KB
testcase_04 AC 4 ms
7,296 KB
testcase_05 AC 3 ms
7,168 KB
testcase_06 AC 4 ms
7,168 KB
testcase_07 AC 4 ms
7,296 KB
testcase_08 AC 4 ms
7,296 KB
testcase_09 AC 3 ms
7,296 KB
testcase_10 AC 4 ms
7,296 KB
testcase_11 AC 4 ms
7,296 KB
testcase_12 AC 4 ms
7,168 KB
testcase_13 AC 4 ms
7,296 KB
testcase_14 AC 4 ms
7,296 KB
testcase_15 AC 4 ms
7,168 KB
testcase_16 AC 4 ms
7,168 KB
testcase_17 AC 3 ms
7,168 KB
testcase_18 AC 3 ms
7,296 KB
testcase_19 AC 4 ms
7,168 KB
testcase_20 AC 4 ms
7,296 KB
testcase_21 AC 5 ms
7,552 KB
testcase_22 AC 6 ms
7,552 KB
testcase_23 AC 4 ms
7,424 KB
testcase_24 AC 4 ms
7,296 KB
testcase_25 AC 5 ms
7,552 KB
testcase_26 AC 5 ms
7,552 KB
testcase_27 AC 5 ms
7,552 KB
testcase_28 AC 191 ms
21,336 KB
testcase_29 AC 188 ms
21,336 KB
testcase_30 AC 195 ms
21,208 KB
testcase_31 AC 207 ms
21,336 KB
testcase_32 AC 126 ms
21,336 KB
testcase_33 AC 80 ms
19,260 KB
testcase_34 AC 118 ms
21,208 KB
testcase_35 AC 180 ms
21,204 KB
testcase_36 AC 124 ms
21,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#define llint long long
#define inf 1e18

using namespace std;
typedef pair<llint, llint> P;

struct SegTree{
	int size;
	vector<llint> seg;
	
	SegTree(){}
	SegTree(int size){
		this->size = size;
		seg.resize(1<<(size+1));
	}
	
	void init()
	{
		for(int i = 0; i < (1<<(size+1)); i++) seg[i] = -inf;
	}
	
	void update(int i, llint val)
	{
		i += (1 << size);
		seg[i] = val;
		while(i > 1){
			i /= 2;
			seg[i] = max(seg[i*2], seg[i*2+1]);
		}
	}

	llint query(int a, int b, int k, int l, int r)
	{
		if(b < l || r < a) return -inf;
		if(a <= l && r <= b) return seg[k];
		llint lval = query(a, b, k*2, l, (l+r)/2);
		llint rval = query(a, b, k*2+1, (l+r)/2+1, r);
		return max(lval, rval);
	}
	llint query(int a, int b)
	{
		return query(a, b, 1, 0, (1<<size)-1);
	}
};

llint n;
llint a[200005], b[200005], c[200005];
vector<pair<P, llint> > vec;
vector<llint> comp;
SegTree seg(18);

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i] >> b[i] >> c[i];
	
	for(int i = 0; i <= n; i++) comp.push_back(b[i]);
	sort(comp.begin(), comp.end());
	comp.erase(unique(comp.begin(), comp.end()), comp.end());
	for(int i = 1; i <= n; i++) b[i] = lower_bound(comp.begin(), comp.end(), b[i]) - comp.begin();
	
	for(int i = 1; i <= n; i++) vec.push_back(make_pair(make_pair(a[i], -b[i]), c[i]));
	sort(vec.begin(), vec.end());
	for(int i = (int)vec.size()-2; i >= 0; i--){
		if(vec[i].first == vec[i+1].first) vec[i].second = 0;
	}
	
	seg.init();
	seg.update(0, 0);
	for(int i = 0; i < vec.size(); i++){
		int p = -vec[i].first.second;
		seg.update(p, max(seg.query(p, p), seg.query(0, p-1) + vec[i].second) );
	}
	
	cout << seg.query(1, vec.size()) << endl;
	return 0;
}
0