Submission #944916

#TimeUsernameProblemLanguageResultExecution timeMemory
944916siewjhTriple Jump (JOI19_jumps)C++17
0 / 100
4054 ms19932 KiB
#include <bits/stdc++.h> using namespace std; struct node{ int s, e, m, val; node *l, *r; node (int _s, int _e){ s = _s, e = _e, m = (s + e) >> 1, val = 0; if (s != e){ l = new node(s, m); r = new node(m + 1, e); } } void update(int p, int v){ val = max(val, v); if (s == e) return; else if (p <= m) l->update(p, v); else r->update(p, v); } int query(int x, int y){ if (x == s && y == e) return val; else if (y <= m) return l->query(x, y); else if (x > m) return r->query(x, y); else return max(l->query(x, m), r->query(m + 1, y)); } }; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int nums; cin >> nums; vector<int> vec(nums + 1); for (int i = 1; i <= nums; i++) cin >> vec[i]; int queries; cin >> queries; vector<tuple<int, int, int>> qvec(queries); for (int i = 0; i < queries; i++){ int l, r; cin >> l >> r; qvec[i] = {r, l, i}; } sort(qvec.begin(), qvec.end()); vector<int> ans(queries); node *root = new node(1, nums); int curr = 2; for (auto [r, l, qind] : qvec){ while (curr <= r){ curr++; for (int i = curr - 2; i >= 1; i--) root->update(i, vec[i] + vec[(i + curr) >> 1] + vec[curr]); } ans[qind] = root->query(l, r); } for (int x : ans) cout << x << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...