Submission #125601

#TimeUsernameProblemLanguageResultExecution timeMemory
125601srvltDivide and conquer (IZhO14_divide)C++14
17 / 100
32 ms10744 KiB
#include <bits/stdc++.h> #define ll long long #define db long double #define pb push_back #define ppb pop_back #define fi first #define se second #define mp make_pair #define endl "\n" #define int long long #define val(x) (((x) == nullptr) ? 0 : (x -> m)) #define left(x) (((x) == nullptr) ? nullptr : (x -> l)) #define right(x) (((x) == nullptr) ? nullptr : (x -> r)) using namespace std; const int N = 1e5 + 3, M = 2e9; int n, x[N], d[N], g[N], v[N], ans; struct node { node * l, * r; int m; node(node * l, node * r, int m = 0) { this -> l = l; this -> r = r; this -> m = m + max(val(l), val(r)); } }; node * root = new node(nullptr, nullptr); node * update(node * t, int tl, int tr, int x, int y) { if (tl == tr) { return new node(nullptr, nullptr, y); } int tm = (tl + tr) >> 1LL; if (x <= tm) { return new node(update(left(t), tl, tm, x, y), right(t)); } else { return new node(left(t), update(right(t), tm + 1, tr, x, y)); } } int getmax(node * t, int tl, int tr, int l, int r) { if (tl > r || tr < l) { return 0; } if (tl >= l && tr <= r) { return val(t); } int tm = (tl + tr) >> 1LL; return max(getmax(left(t), tl, tm, l, r), getmax(right(t), tm + 1, tr, l, r)); } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>n; for (int i = 1; i <= n; i++) { cin>>x[i]>>g[i]>>d[i]; g[i] += g[i - 1]; d[i] += d[i - 1]; v[i] = d[i] - x[i]; } for (int i = n; i >= 1; i--) { int tmp = d[i - 1] - x[i]; root = update(root, 0, M, v[i] + (int) 1e9, i); int res = getmax(root, 0, M, tmp + (int) 1e9, M); ans = max(ans, g[res] - g[i - 1]); } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...