Submission #941692

#TimeUsernameProblemLanguageResultExecution timeMemory
941692emptypringlescanTriple Jump (JOI19_jumps)C++17
32 / 100
4046 ms9428 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main(){ ios::sync_with_stdio(0);cin.tie(0); int n; cin >> n; long long arr[n]; for(int i=0; i<n; i++) cin >> arr[i]; int q; cin >> q; while(q--){ int l,r; cin >> l >> r; l--; r--; long long suf[n]; suf[r]=arr[r]; for(int i=r-1; i>=l; i--) suf[i]=max(suf[i+1],arr[i]); vector<pair<long long,int> > mono; long long ans=0; for(int i=l; i<=r; i++){ while(!mono.empty()&&mono.back().first<=arr[i]){ int a=mono.back().second; if(i*2-a<=r) ans=max(ans,arr[a]+arr[i]+suf[i*2-a]); mono.pop_back(); } if(!mono.empty()){ int a=mono.back().second; if(i*2-a<=r) ans=max(ans,arr[a]+arr[i]+suf[i*2-a]); } mono.push_back({arr[i],i}); } 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...