Submission #163898

#TimeUsernameProblemLanguageResultExecution timeMemory
163898ho94949Triple Jump (JOI19_jumps)C++17
27 / 100
100 ms9572 KiB
#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)

jumps.cpp: In function 'int main()':
jumps.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
jumps.cpp:63:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=0; i<N; ++i) scanf("%d", A+i);
                            ~~~~~^~~~~~~~~~~
jumps.cpp:64:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int Q; scanf("%d", &Q); assert(Q==1);
            ~~~~~^~~~~~~~~~
jumps.cpp:65:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int L, R; scanf("%d%d", &L, &R);
               ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...