Submission #339194

#TimeUsernameProblemLanguageResultExecution timeMemory
339194FlashGamezzzDivide and conquer (IZhO14_divide)C++17
100 / 100
130 ms15068 KiB
#include <iostream> #include <cstdlib> #include <cstdio> #include <fstream> #include <algorithm> #include <utility> #include <vector> #include <string> #include <iostream> #include <map> using namespace std; int n, k, stree[300000] = {}; vector<pair<int, pair<int, int > > > mines; vector<long long> gld, svs; vector<pair<long long, int> > nrg; map<long long, int> cc; void updh(int i, int s, int e, int l, int u, int d) { if (s > e || s > u || e < l) { return; } if (s >= l && e <= u) { stree[i] = max(stree[i], d); return; } updh(i*2+1, s, (s+e)/2, l, u, d); updh(i*2+2, (s+e)/2+1, e, l, u, d); stree[i] = max(stree[i*2+1], stree[i*2+2]); } void updv(int i, int d) { updh(0, 0, n, i, i, d); } int maxh(int i, int s, int e, int l, int u) { if (s > e || s > u || e < l) { return 0; } if (s >= l && e <= u) { return stree[i]; } return max(maxh(2*i+1, s, (s+e)/2, l, u), maxh(2*i+2, (s+e)/2+1, e, l, u)); } int maxv(int l, int u) { return maxh(0, 0, n, l, u); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 0; i < n; i++){ int a, b, c; cin >> a >> b >> c; mines.push_back(make_pair(a, make_pair(b, c))); } int last = 0; gld.push_back(0); nrg.push_back(make_pair(0, 0)); for (int i = 0; i < n; i++){ int x = mines[i].first, cnrg = mines[i].second.second, cgld = mines[i].second.first; nrg.push_back(make_pair(cnrg+nrg[i].first+last-x, i+1)); svs.push_back(nrg[i].first-x+last); last = x; gld.push_back(gld[i]+cgld); } sort(nrg.begin(), nrg.end()); for (int i = 0; i <= n; i++){ cc[nrg[i].first] = i; } for (int i = 0; i <= n; i++){ updv(cc[nrg[i].first], nrg[i].second); } long long ans = 0; for (int i = 0; i < n; i++){ ans = max(ans, gld[maxv(cc.lower_bound(svs[i])->second, n)]-gld[i]); } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...