# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
944025 | teacup | Triple Jump (JOI19_jumps) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int,int>
typedef vector<int> vi;
#define iii tuple<int,int,int>
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef map<int,int> mii;
#ifndef debug
#define cerr if (0) cerr
#endif
const int INF=1e17;
template<class T>
struct RMQ{
vector<vector<T>> jmp;
RMQ(const vector<T>&V) : jmp(1,V){
for (int pw=1, k=1; pw*2<=V.size(); pw*=2, k++){
jmp.emplace_back(size(V) - pw*2+1);
for (int j=0; j<jmp[k].size(); j++){
jmp[k][j] = max(jmp[k-1][j], jmp[k-1][j+pw]);
}
}
}
T query(int a, int b){
if (a>=b) return -INF;
int dep = 31 - __builtin_clz(b-a);
return max(jmp[dep][a], jmp[dep][b-(1<<dep)]);
}
};
int N, Q, L, R, ans;
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>N; vi A(N+5);
for (int i=1; i<=N; i++){
cin>>A[i];
}
RMQ<int> rmq(A);
cin>>Q;
while (Q--){
cin>>L>>R;
ans = 0;
for (int i=L; i<=R; i++){
for (int j=i+1; j<=R; j++){
/*
for (int k=j+1; k<=R; k++){
if (!(j-i <= k-j)) continue;
ans=max(ans, A[i]+A[j]+A[k]);
}*/
ans=max(ans, A[i]+A[j]+rmq.query(2*j-i, R));
}
}
cout<<ans<<"\n";
}
}