結果

問題 No.777 再帰的ケーキ
ユーザー aonek0aonek0
提出日時 2019-06-13 17:38:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 362 ms / 2,000 ms
コード長 2,377 bytes
コンパイル時間 1,141 ms
コンパイル使用メモリ 112,028 KB
実行使用メモリ 21,444 KB
最終ジャッジ日時 2024-04-22 17:51:37
合計ジャッジ時間 6,147 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,296 KB
testcase_01 AC 4 ms
7,424 KB
testcase_02 AC 4 ms
7,424 KB
testcase_03 AC 4 ms
7,296 KB
testcase_04 AC 4 ms
7,296 KB
testcase_05 AC 4 ms
7,424 KB
testcase_06 AC 3 ms
7,424 KB
testcase_07 AC 3 ms
7,424 KB
testcase_08 AC 3 ms
7,296 KB
testcase_09 AC 4 ms
7,424 KB
testcase_10 AC 4 ms
7,296 KB
testcase_11 AC 4 ms
7,424 KB
testcase_12 AC 4 ms
7,424 KB
testcase_13 AC 4 ms
7,168 KB
testcase_14 AC 4 ms
7,424 KB
testcase_15 AC 3 ms
7,424 KB
testcase_16 AC 4 ms
7,424 KB
testcase_17 AC 4 ms
7,296 KB
testcase_18 AC 4 ms
7,296 KB
testcase_19 AC 4 ms
7,296 KB
testcase_20 AC 3 ms
7,296 KB
testcase_21 AC 6 ms
7,424 KB
testcase_22 AC 7 ms
7,552 KB
testcase_23 AC 5 ms
7,424 KB
testcase_24 AC 5 ms
7,552 KB
testcase_25 AC 7 ms
7,424 KB
testcase_26 AC 7 ms
7,552 KB
testcase_27 AC 6 ms
7,424 KB
testcase_28 AC 321 ms
21,316 KB
testcase_29 AC 315 ms
21,308 KB
testcase_30 AC 356 ms
21,344 KB
testcase_31 AC 362 ms
21,440 KB
testcase_32 AC 268 ms
21,312 KB
testcase_33 AC 156 ms
19,368 KB
testcase_34 AC 225 ms
21,316 KB
testcase_35 AC 339 ms
21,312 KB
testcase_36 AC 260 ms
21,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
#include <limits>
#include <numeric>
#include<string.h>
#include<set>
using namespace std;
#define ll long long int
#define all(v) begin(v), end(v)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
//typedef vector<int> V;
//typedef vector<V> VV;
//typedef vector<VV> VVV;
using namespace std;



#define llint long long
#define inf 1e18

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(){

	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 = 0; i < n; i++)cout << vec[i].first.first << " " << vec[i].first.second << endl;


	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