# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
163898 | ho94949 | Triple Jump (JOI19_jumps) | C++17 | 100 ms | 9572 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;
const int MAXN = 524288;
int N;
int A[MAXN];
int nv[MAXN];
int idx[2*MAXN];
int getv(int a, int b)
{
a += MAXN; b += MAXN;
int ans = 0;
while(a<=b)
{
if(a%2==1) ans = max(ans, idx[a++]);
if(b%2==0) ans = max(ans, idx[b--]);
a/=2; b/=2;
}
return ans;
}
void setv(int a, int v)
{
idx[a+=MAXN] = v;
while((a=a/2))
idx[a] = max(idx[2*a], idx[2*a+1]);
}
int solve()
{
A[N] = (int)1e8+1;
stack<int> S;
for(int i=0; i<=N; ++i)
{
setv(i, A[i]);
while(!S.empty() && A[S.top()] < A[i])
{
nv[S.top()] = i; S.pop();
}
S.push(i);
}
vector<pair<int, int> > ab;
for(int a=0; a<N-1; ++a)
{
int b = a+1;
ab.emplace_back(a, b);
while(nv[b] != N && A[b]<A[a])
{
b = nv[b];
ab.emplace_back(a, b);
}
}
int ret = 0;
for(auto [a, b]: ab)
{
int cind = 2*b-a;
int ans = A[a] + A[b] + getv(cind, N-1);
ret = max(ret, ans);
}
return ret;
}
int main()
{
scanf("%d", &N);
for(int i=0; i<N; ++i) scanf("%d", A+i);
int Q; scanf("%d", &Q); assert(Q==1);
int L, R; scanf("%d%d", &L, &R);
assert(L==1&&R==N);
printf("%d\n", solve());
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |