結果

問題 No.777 再帰的ケーキ
ユーザー tarakojo1019tarakojo1019
提出日時 2021-01-18 19:45:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,029 ms / 2,000 ms
コード長 3,085 bytes
コンパイル時間 1,661 ms
コンパイル使用メモリ 139,484 KB
実行使用メモリ 55,752 KB
最終ジャッジ日時 2023-08-21 02:55:25
合計ジャッジ時間 9,565 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 6 ms
4,384 KB
testcase_22 AC 6 ms
4,380 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 6 ms
4,380 KB
testcase_26 AC 6 ms
4,380 KB
testcase_27 AC 4 ms
4,376 KB
testcase_28 AC 985 ms
55,480 KB
testcase_29 AC 973 ms
55,752 KB
testcase_30 AC 1,029 ms
55,400 KB
testcase_31 AC 1,024 ms
55,444 KB
testcase_32 AC 497 ms
55,444 KB
testcase_33 AC 106 ms
10,300 KB
testcase_34 AC 155 ms
11,924 KB
testcase_35 AC 593 ms
33,972 KB
testcase_36 AC 487 ms
55,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<numeric>
#include<cstring>
#include<random>
#include<array>
#include<fstream>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include<queue>

/*
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

using namespace std;

using ll = long long;
using ull = unsigned long long;

#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define PRI(s) std::cout << s << endl
#define PRIF(v, n) printf("%."#n"f\n", (double)v)

template<typename A, typename B>void mins(A& a, const B& b) { a = min(a, (A)b); };
template<typename A, typename B>void maxs(A& a, const B& b) { a = max(a, (A)b); };



template<typename X>
class segtree {
public:
	using func_xx = function<X(X, X)>;
	long long N;
	func_xx fxx;
	X ex;
	vector<X> dat;
	bool changed;

	segtree() {}
	segtree(long long n, func_xx fxx, const X& ex) : fxx(fxx), ex(ex), changed(false) {
		if (n == 1) ++n;
		int x = 1;
		while (x < n) x *= 2;
		N = x;
		dat.resize(2 * N - 1, ex);
	}
	const segtree<X>& operator=(const segtree& source) {
		N = source.N;
		fxx = source.fxx;
		ex = source.ex;
		dat = source.dat;
		changed = source.changed;
		return *this;
	}
	//代入後のデータ更新
	void update(int k) {
		dat[k] = fxx(dat[2 * k + 1], dat[2 * k + 2]);
		if (k != 0) update((k - 1) / 2);
	}
	void build() {
		for (int i = N - 2; i >= 0; --i) dat[i] = fxx(dat[2 * i + 1], dat[2 * i + 2]);
		changed = false;
	}
	//要素の代入
	void set(int i, const X& x, bool update = true) {
		dat[N - 1 + i] = x;
		if (update) this->update((N - 2 + i) / 2);
		else changed = true;
	}
	//要素の参照
	const X& elem(int i) {
		return dat[N - 1 + i];
	}
	X query_sub(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) { return ex; }
		else if (a <= l && r <= b) { return dat[k]; }
		else {
			return fxx(query_sub(a, b, 2 * k + 1, l, (l + r) / 2),
				query_sub(a, b, 2 * k + 2, (l + r) / 2, r));
		}
	}
	//[a,b)間のクエリfxx
	X query(int a, int b) {
		if (changed) build();
		return query_sub(a, b, 0, 0, N);
	}
};


int main() {
	auto func = [](ll a, ll b) {return max(a, b); };
	ll N; cin >> N;
	vector<tuple<ll, ll, ll>> abc(N);
	map<ll, map<ll, ll, greater<ll>>> mp;
	map<ll, ll> ind;
	REP(i, 0, N) {
		ll a, b, c; cin >> a >> b >> c;
		abc[i] = { a,-b,c };
		ind[b] = 0;
		maxs(mp[a][b], c);
	}
	ll c = 0;
	for (auto& p : ind) p.second = c++;


	/*
	sort(abc.begin(), abc.end());

	c = 0;
	pair<ll, ll> last = { 0,0 };
	auto cmp = [](auto a, auto b) {if (a.first == b.first) return a.second > b.second; else return a.first < b.first; };
	*/

	segtree<ll> seg{ N, func, 0 };

	for (auto& v : mp)for (auto p : v.second) {
		//for (auto& v : abc) {
		//auto [a, b, c] = v;

		ll b = -p.first;
		ll c = p.second;

		ll tmp = seg.query(0, ind[-b]);
		if (seg.elem(ind[-b]) < tmp + c) seg.set(ind[-b], tmp + c);
	}
	PRI(seg.query(0, N));

	return 0;
}
0