結果

問題 No.777 再帰的ケーキ
ユーザー 25__toma25__toma
提出日時 2019-03-26 04:40:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 461 ms / 2,000 ms
コード長 1,785 bytes
コンパイル時間 2,195 ms
コンパイル使用メモリ 180,416 KB
実行使用メモリ 25,776 KB
最終ジャッジ日時 2024-04-19 07:20:11
合計ジャッジ時間 7,208 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
11,572 KB
testcase_01 AC 5 ms
11,460 KB
testcase_02 AC 5 ms
11,508 KB
testcase_03 AC 5 ms
11,468 KB
testcase_04 AC 4 ms
11,472 KB
testcase_05 AC 4 ms
11,456 KB
testcase_06 AC 4 ms
11,476 KB
testcase_07 AC 5 ms
11,432 KB
testcase_08 AC 5 ms
11,464 KB
testcase_09 AC 5 ms
11,572 KB
testcase_10 AC 5 ms
11,508 KB
testcase_11 AC 5 ms
11,368 KB
testcase_12 AC 4 ms
11,512 KB
testcase_13 AC 5 ms
11,640 KB
testcase_14 AC 5 ms
11,484 KB
testcase_15 AC 5 ms
11,456 KB
testcase_16 AC 5 ms
11,392 KB
testcase_17 AC 5 ms
11,460 KB
testcase_18 AC 5 ms
11,396 KB
testcase_19 AC 5 ms
11,432 KB
testcase_20 AC 5 ms
11,392 KB
testcase_21 AC 8 ms
11,532 KB
testcase_22 AC 7 ms
11,504 KB
testcase_23 AC 6 ms
11,580 KB
testcase_24 AC 6 ms
11,560 KB
testcase_25 AC 8 ms
11,568 KB
testcase_26 AC 9 ms
11,576 KB
testcase_27 AC 8 ms
11,676 KB
testcase_28 AC 413 ms
25,572 KB
testcase_29 AC 411 ms
25,544 KB
testcase_30 AC 461 ms
25,720 KB
testcase_31 AC 461 ms
25,776 KB
testcase_32 AC 313 ms
25,428 KB
testcase_33 AC 207 ms
20,796 KB
testcase_34 AC 317 ms
25,492 KB
testcase_35 AC 448 ms
25,648 KB
testcase_36 AC 310 ms
25,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include"bits/stdc++.h"

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7




class SegmentTree {
public:
	SegmentTree(ll size)
	{
		n = 1;
		while (n < size)n *= 2;
		dat.resize(n * 2, 0);
	}
	void update(ll k, ll a)
	{
		//葉の接点
		k += n - 1;
		dat[k] = a;
		//登りながら更新
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}
	ll query(ll a, ll b) {
		return query_impl(a, b, 0, 0, n);
	}
private:
	ll n;
	vector<ll> dat;
	ll query_impl(ll a, ll b, ll k, ll l, ll r)
	{
		if (r <= a || b <= l)return 0;
		if (a <= l && r <= b)return dat[k];
		else {
			ll vl = query_impl(a, b, k * 2 + 1, l, (l + r) / 2);
			ll vr = query_impl(a, b, k * 2 + 2, (l + r) / 2, r);
			return max(vl, vr);
		}
	}
};

int main()
{
	ll N;
	cin >> N;
	vector<vector<ll>> abc(N);
	vector<ll> v, v2;
	REP(i, N) {
		ll a, b, c;
		cin >> a >> b >> c;
		abc[i] = { a, -b,c };
		v.push_back(b);
	}
	v2.resize(N, 0);
	sort(abc.begin(), abc.end());
	sort(v.begin(), v.end());

	// zaatu
	for (auto& row : abc) {
		row[1] *= -1;
		ll b = row[1];
		auto itr = upper_bound(v.begin(), v.end(), b);
		--itr;
		assert(*itr == b);
		ll dist = itr - v.begin();
		row[1] = dist - v2[dist] + 1;
		v2[dist]++;
	}

	SegmentTree st(3e5);
	for (auto row : abc) {
		ll key = row[1];
		ll value = row[2];
		ll max = st.query(1, key);
		st.update(key, max + value);
	}
	cout << st.query(1, N + 1) << endl;

	return 0;
}
0