Submission #489449

#TimeUsernameProblemLanguageResultExecution timeMemory
489449fhvirusTriple Jump (JOI19_jumps)C++17
0 / 100
30 ms1944 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define ff first #define ss second #define pb emplace_back #define AI(x) begin(x),end(x) template<class I> bool chmin(I&a, I b){ return a > b ? (a=b, true) : false; } template<class I> bool chmax(I&a, I b){ return a < b ? (a=b, true) : false; } #ifdef OWO #define debug(args...) LKJ("\033[1;32m[ " + string(#args) + " ]\033[0m", args) template<class I> void LKJ(I&&x){ cerr << x << endl; } template<class I, class...T> void LKJ(I&&x, T&&...t){ cerr << x << ", "; LKJ(t...); } template<class I> void OI(I a, I b){ while(a < b) cerr << *a << " \n"[next(a) == b], ++a; } #else #define debug(...) 0 #define OI(...) 0 #endif const int kN = 500005; int N, Q, A[kN]; int L[kN], R[kN]; void input(){ cin >> N; for(int i = 1; i <= N; ++i) cin >> A[i]; cin >> Q; for(int i = 0; i < Q; ++i) cin >> L[i] >> R[i]; } int suf[kN]; int f(int a, int b){ return A[a] + A[b] + suf[ b + (b-a) ]; } void solve(){ suf[N] = A[N]; for(int i = N-1; i >= 1; --i) suf[i] = max(A[i], suf[i+1]); int ans = 0; deque<int> dq; for(int i = 2; i < N; ++i){ while(!dq.empty() and f(dq.back(), i) <= f(i-1, i)) dq.pop_back(); dq.pb(i-1); while(dq.size() > 1 and f(dq[0], i) <= f(dq[1], i)) dq.pop_front(); chmax(ans, f(dq[0], i)); } cout << ans << '\n'; } signed main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); input(); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...