結果
問題 | No.1826 Fruits Collecting |
ユーザー | ei1333333 |
提出日時 | 2022-01-28 23:07:20 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 6,132 bytes |
コンパイル時間 | 5,062 ms |
コンパイル使用メモリ | 287,460 KB |
実行使用メモリ | 95,332 KB |
最終ジャッジ日時 | 2024-06-09 16:38:40 |
合計ジャッジ時間 | 29,071 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 2 ms
6,940 KB |
testcase_26 | AC | 2 ms
6,940 KB |
testcase_27 | AC | 2 ms
6,940 KB |
testcase_28 | AC | 2 ms
6,940 KB |
testcase_29 | AC | 2 ms
6,944 KB |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | AC | 89 ms
11,228 KB |
testcase_38 | AC | 63 ms
8,740 KB |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | AC | 2 ms
6,940 KB |
testcase_44 | AC | 2 ms
6,940 KB |
testcase_45 | AC | 2 ms
6,944 KB |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using int64 = long long; // const int mod = 1e9 + 7; const int mod = 998244353; const int64 infll = (1LL << 62) - 1; const int inf = (1 << 30) - 1; struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup; template< typename T1, typename T2 > ostream &operator<<(ostream &os, const pair< T1, T2 > &p) { os << p.first << " " << p.second; return os; } template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; } template< typename T > ostream &operator<<(ostream &os, const vector< T > &v) { for(int i = 0; i < (int) v.size(); i++) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } template< typename T > istream &operator>>(istream &is, vector< T > &v) { for(T &in: v) is >> in; return is; } template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } template< typename T = int64 > vector< T > make_v(size_t a) { return vector< T >(a); } template< typename T, typename... Ts > auto make_v(size_t a, Ts... ts) { return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...)); } template< typename T, typename V > typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) { t = v; } template< typename T, typename V > typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) { for(auto &e: t) fill_v(e, v); } template< typename F > struct FixPoint : F { FixPoint(F &&f) : F(forward< F >(f)) {} template< typename... Args > decltype(auto) operator()(Args &&... args) const { return F::operator()(*this, forward< Args >(args)...); } }; template< typename F > inline decltype(auto) MFP(F &&f) { return FixPoint< F >{forward< F >(f)}; } /** * @brief Binary-Indexed-Tree(BIT) * @docs docs/binary-indexed-tree.md */ struct BinaryIndexedTree { private: vector< int64 > data; public: explicit BinaryIndexedTree(size_t sz) : data(sz + 1, -infll) {} void add(int k, const int64 &x) { for(++k; k < (int) data.size(); k += k & -k) data[k] = max(data[k], x); } int64 fold(int r) const { int64 ret = -infll; for(; r > 0; r -= r & -r) ret = max(ret, data[r]); return ret; } }; template< typename structure_t, typename get_t, typename update_t, typename merge_f, typename range_get_f, typename update_f > struct SegmentTree2DCompressed2 { int sz; vector< structure_t > seg; const merge_f f; const range_get_f g; const update_f h; const get_t identity; vector< vector< int > > beet; SegmentTree2DCompressed2(int n, const merge_f &f, const range_get_f &g, const update_f &h, const get_t &identity) : f(f), g(g), h(h), identity(identity) { beet.resize(n + 1); } void update(int k, int y, update_t z) { for(++k; k < (int) beet.size(); k += k & -k) { auto y2 = lower_bound(begin(beet[k]), end(beet[k]), y) - begin(beet[k]); h(seg[k], y2, z); } } get_t query(int k, int y) { get_t ret = identity; for(; k > 0; k -= k & -k) { auto y2 = lower_bound(begin(beet[k]), end(beet[k]), y) - begin(beet[k]); ret = f(ret, g(seg[k], y2)); } return ret; } void build() { for(int k = 0; k < (int) beet.size(); k++) { beet[k].erase(unique(begin(beet[k]), end(beet[k])), end(beet[k])); seg.emplace_back(beet[k].size()); } } void preupdate(int k, int y) { for(++k; k < (int) beet.size(); k += k & -k) { beet[k].emplace_back(y); } } }; int main() { int N; cin >> N; vector< tuple< int, int, int > > ds; ds.reserve(N + 1); for(int i = 0; i < N; i++) { int t, x, v; cin >> t >> x >> v; ds.emplace_back(t, x, v); } ds.emplace_back(0, 0, 0); sort(begin(ds), end(ds)); vector< int64 > dp(ds.size(), -infll); dp[0] = 0; vector< int > l, r, m; l.reserve(N + 1); r.reserve(N + 1); m.reserve(N + 1); for(auto&[t, x, v]: ds) { l.emplace_back(t + x); r.emplace_back(t - x); m.emplace_back(x); } sort(begin(l), end(l)); l.erase(unique(begin(l), end(l)), end(l)); sort(begin(r), end(r)); r.erase(unique(begin(r), end(r)), end(r)); sort(begin(m), end(m)); m.erase(unique(begin(m), end(m)), end(m)); vector< int > ldx(ds.size()), rdx(ds.size()), mdx(ds.size()); for(int i = 0; i < (int) ds.size(); i++) { auto[t, x, v]=ds[i]; ldx[i] = lower_bound(begin(l), end(l), t + x) - begin(l); rdx[i] = lower_bound(begin(r), end(r), t - x) - begin(r); mdx[i] = lower_bound(begin(m), end(m), x) - begin(m); } auto f = [](int64 a, int64 b) { return max(a, b); }; // みんなの2D segment tree // たすけて~~~~~ using BIT = BinaryIndexedTree; auto g = [](BIT &k, int y) { return k.fold(y); }; auto h = [](BIT &k, int x, int64 y) { k.add(x, y); }; SegmentTree2DCompressed2< BIT, int64, int64, decltype(f), decltype(g), decltype(h) > lseg(m.size(), f, g, h, -infll); SegmentTree2DCompressed2< BIT, int64, int64, decltype(f), decltype(g), decltype(h) > rseg(m.size(), f, g, h, -infll); vector< int > ord(ds.size()); iota(begin(ord), end(ord), 0); sort(begin(ord), end(ord), [&](int a, int b) { return rdx[a] < rdx[b]; }); for(int i: ord) rseg.preupdate(mdx[i], rdx[i]); sort(begin(ord), end(ord), [&](int a, int b) { return ldx[a] < ldx[b]; }); for(int i: ord) lseg.preupdate(mdx[i], ldx[i]); lseg.build(); rseg.build(); lseg.update(m.size() - mdx[0] - 1, ldx[0], 0); rseg.update(mdx[0], rdx[0], 0); int64 ret = 0; for(int i = 1; i < (int) ds.size(); i++) { auto[t2, x2, v2] = ds[i]; auto v = max(lseg.query(m.size() - mdx[i], ldx[i] + 1), rseg.query(mdx[i], rdx[i] + 1)); v += v2; if(v >= 0) { chmax(ret, v); lseg.update(m.size() - mdx[i] - 1, ldx[i], v); rseg.update(mdx[i], rdx[i], v); } } cout << ret << "\n"; }