제출 #1134732

#제출 시각아이디문제언어결과실행 시간메모리
1134732JelalTkm금 캐기 (IZhO14_divide)C++20
17 / 100
1 ms328 KiB
#include <bits/stdc++.h> #pragma GCC optimize ("O3") #pragma GCC target ("sse4") using namespace std; #define int long long int const int N = 1e6 + 10; const int md = 1e9 + 7; const int INF = 1e18; struct node { int x, g, d; }; struct segtree { vector<pair<int, int>> tree, tree1; int size; void init(int n) { size = 1; while (size < n) size <<= 1; tree.assign(2 * size - 1, {INF, 0}); tree1.assign(2 * size - 1, {INF, 0}); } void build(vector<int> &a, int x, int lx, int rx) { if (rx - lx == 1) { if (lx < (int) a.size() && lx) { tree[x].first = a[lx]; tree[x].second = lx; if (tree1[x].first >= 0) tree1[x].first = a[lx]; else tree1[x].first = INF; tree1[x].second = lx; } } else { int m = (lx + rx) >> 1; build(a, 2 * x + 1, lx, m); build(a, 2 * x + 2, m, rx); if (tree[2 * x + 1].first <= tree[2 * x + 2].first) tree[x] = tree[2 * x + 1]; else tree[x] = tree[2 * x + 2]; if (tree1[2 * x + 1].first <= tree1[2 * x + 2].first) tree1[x] = tree1[2 * x + 1]; else tree1[x] = tree1[2 * x + 2]; } } void build(vector<int> &a) { init((int) a.size()); build(a, 0, 0, size); } pair<int, int> get(int l, int r, int y, int x, int lx, int rx) { if (l >= rx || lx >= r) { return {INF, -1}; } if (lx >= l && rx <= r) { return tree[x]; } int m = (lx + rx) >> 1; auto s1 = get(l, r, y, 2 * x + 1, lx, m); auto s2 = get(l, r, y, 2 * x + 2, m, rx); if ((y - s1.first) >= 0) return s1; else return s2; } pair<int, int> get(int r, int y) { auto pr = get(1, r, y, 0, 0, size); return pr; } pair<int, int> get1(int l, int r, int y, int x, int lx, int rx) { if (l >= rx || lx >= r) { return {INF, -1}; } if (lx >= l && rx <= r) { return tree1[x]; } int m = (lx + rx) >> 1; auto s1 = get1(l, r, y, 2 * x + 1, lx, m); auto s2 = get1(l, r, y, 2 * x + 2, m, rx); if ((y - s1.first) >= 0) return s1; else return s2; } pair<int, int> get1(int r, int y) { auto pr = get1(1, r, y, 0, 0, size); return pr; } }; int32_t main(int32_t argc, char *argv[]) { ios::sync_with_stdio(false); cin.tie(nullptr); int T = 1; // cin >> T; while (T--) { int n; cin >> n; vector<node> a(n + 1); for (int i = 1; i <= n; i++) cin >> a[i].x >> a[i].g >> a[i].d; vector<int> pref_d(n + 1), pref_g(n + 1), prefd(n + 1); for (int i = 1; i <= n; i++) { pref_d[i] = pref_d[i - 1] + a[i].d; pref_g[i] = pref_g[i - 1] + a[i].g; prefd[i] = pref_d[i - 1] - a[i].x; } segtree st; st.build(prefd); int ans = pref_g[1]; for (int i = 2; i <= n; i++) { int y = pref_d[i] - a[i].x; auto x = st.get(i, y); auto x1 = st.get1(i, y); if (y - x.first >= 0) ans = max(ans, pref_g[i] - pref_g[x.second - 1]); if (y - x1.first >= 0) ans = max(ans, pref_g[i] - pref_g[x1.second - 1]); ans = max(ans, pref_g[i] - pref_g[i - 1]); } cout << ans << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...