Submission #198974

#TimeUsernameProblemLanguageResultExecution timeMemory
198974osaaateiasavtnlTriple Jump (JOI19_jumps)C++14
5 / 100
4075 ms10336 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define ii pair <int, int> #define app push_back #define all(a) a.begin(), a.end() #define bp __builtin_popcount #define ll long long #define mp make_pair #define f first #define s second #define Time (double)clock()/CLOCKS_PER_SEC const int N = 5e5 + 7; int n, q, a[N]; signed main() { #ifdef HOME freopen("input.txt", "r", stdin); #else ios_base::sync_with_stdio(0); cin.tie(0); #endif cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; vector <ii> p; vector <int> s; for (int i = 0; i < n; ++i) { while (s.size() && a[s.back()] <= a[i]) { p.app(mp(s.back(), i)); s.pop_back(); } s.app(i); } s.clear(); for (int i = n - 1; i >= 0; --i) { while (s.size() && a[s.back()] <= a[i]) { p.app(mp(i, s.back())); s.pop_back(); } s.app(i); } int q; cin >> q; while (q--) { int l, r; cin >> l >> r; --l; --r; int ans = 0; for (auto e : p) { if (l <= e.f && e.s <= r) { for (int i = e.s + (e.s - e.f); i <= r; ++i) ans = max(ans, a[i] + a[e.f] + a[e.s]); } } cout << ans << '\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...