結果
問題 | No.777 再帰的ケーキ |
ユーザー | 🍮かんプリン |
提出日時 | 2020-06-12 18:39:36 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,136 bytes |
コンパイル時間 | 2,788 ms |
コンパイル使用メモリ | 181,984 KB |
実行使用メモリ | 19,092 KB |
最終ジャッジ日時 | 2024-06-24 04:03:53 |
合計ジャッジ時間 | 10,313 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | WA | - |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | WA | - |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 1 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,944 KB |
testcase_14 | AC | 2 ms
6,944 KB |
testcase_15 | AC | 2 ms
6,944 KB |
testcase_16 | AC | 2 ms
6,944 KB |
testcase_17 | AC | 2 ms
6,944 KB |
testcase_18 | WA | - |
testcase_19 | AC | 3 ms
6,940 KB |
testcase_20 | AC | 2 ms
6,944 KB |
testcase_21 | AC | 5 ms
6,940 KB |
testcase_22 | AC | 5 ms
6,944 KB |
testcase_23 | AC | 3 ms
6,940 KB |
testcase_24 | AC | 3 ms
6,940 KB |
testcase_25 | AC | 6 ms
6,940 KB |
testcase_26 | AC | 6 ms
6,940 KB |
testcase_27 | AC | 4 ms
6,944 KB |
testcase_28 | AC | 712 ms
18,988 KB |
testcase_29 | AC | 639 ms
18,888 KB |
testcase_30 | AC | 705 ms
18,864 KB |
testcase_31 | AC | 700 ms
19,040 KB |
testcase_32 | AC | 416 ms
19,092 KB |
testcase_33 | AC | 125 ms
6,940 KB |
testcase_34 | AC | 190 ms
6,944 KB |
testcase_35 | AC | 483 ms
12,264 KB |
testcase_36 | AC | 422 ms
18,952 KB |
ソースコード
/** * @FileName a.cpp * @Author kanpurin * @Created 2020.06.12 18:39:28 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; template < class Monoid > struct SegmentTree { private: using Func = std::function< Monoid(Monoid, Monoid) >; Func F; Monoid UNITY; int n; std::vector< Monoid > node; public: SegmentTree() {} SegmentTree(int m, const Monoid &val, const Func f, const Monoid &unity) { F = f; UNITY = unity; n = 1; while (n < m) n <<= 1; node.resize(n * 2 - 1, UNITY); if (val != UNITY) { for (int i = 0; i < m; i++) node[i] = val; build(); } } SegmentTree(const std::vector< Monoid > &v, const Func f, const Monoid &unity) { F = f; UNITY = unity; int sz = v.size(); n = 1; while (n < sz) n <<= 1; node.resize(n * 2 - 1, UNITY); for (int i = 0; i < sz; i++) node[i + n - 1] = v[i]; build(); } void set(int k, const Monoid &x) { node[n + k - 1] = x; } void build() { for (int i = n - 2; i >= 0; i--) node[i] = F(node[2 * i + 1], node[2 * i + 2]); } void update_query(int x, const Monoid &val) { if (x >= n || x < 0) return; x += n - 1; node[x] = val; while (x > 0) { x = (x - 1) >> 1; node[x] = F(node[2 * x + 1], node[2 * x + 2]); } } /* Monoid query(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; if (r <= a || b <= l) return UNITY; if (a <= l && r <= b) return node[k]; Monoid vl = query(a, b, 2 * k + 1, l, (r - l) / 2 + l); Monoid vr = query(a, b, 2 * k + 2, (r - l) / 2 + l, r); return F(vl, vr); } */ Monoid get_query(int a, int b) { Monoid L = UNITY, R = UNITY; if (a < 0) a = 0; if (b < 0) return UNITY; if (a >= n) return UNITY; if (b >= n) b = n; for (a += n, b += n; a < b; a >>= 1, b >>= 1) { if (a & 1) L = F(L, node[a++ - 1]); if (b & 1) R = F(node[--b - 1], R); } return F(L, R); } Monoid operator[](int x) const { return node[n + x - 1]; } int size() { return n; } void print() { for (int i = 0; i < n; i++) { std::cout << i << "\t: " << node[n + i - 1] << std::endl; } } }; int main() { int n;cin >> n; vector<tuple<int,int,int>> a(n); map<int,int> mp; for (int i = 0; i < n; i++) { int x,y,z;cin >> x >> y >> z; a[i] = make_tuple(x,y,z); mp[y] = 0; } int t = 0; for(auto p : mp) { mp[p.first] = t++; } sort(a.begin(), a.end()); SegmentTree<ll> seg(t,0,[](ll a,ll b){return max(a,b);},0); ll ans = 0; for (int i = 0; i < n; i++) { seg.update_query(mp[get<1>(a[i])],max(seg[mp[get<1>(a[i])]],seg.get_query(0,mp[get<1>(a[i])]) + get<2>(a[i]))); ans = max(ans,seg[mp[get<1>(a[i])]]); } cout << ans << endl; return 0; }