Submission #933289

#TimeUsernameProblemLanguageResultExecution timeMemory
933289De3b0oTriple Jump (JOI19_jumps)C++14
27 / 100
64 ms16108 KiB
#include<bits/stdc++.h> #define ll long long #define F first #define S second #define in insert #define er erase #define pb push_back #define ppb pop_back() #define ph push #define pp pop() #define d3 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define cans cout << ans << "\n"; #define yes cout << "YES" << "\n"; #define no cout << "NO" << "\n"; #define pll pair<ll,ll> #define lin cout << "\n"; #define sqr 340 #define mod 1000000007 #define mid ((l+r)/2) #define lc (2*n) #define rc (2*n+1) using namespace std; ll fp(ll x , ll y) { if(y==0) return 1; ll z = fp(x,y/2); if(y&1) return z*z*x; else return z*z; } int sqrot(ll x) { int l = 0 , r = INT_MAX; while(l<=r) { if(mid*mid>=x) r=mid-1; else l=mid+1; } return r+1; } ll cel(ll x , ll y) { return x/y + bool(x/y); } string tb(ll x) { string s = ""; while(x>0) { if(x&1) s+='1'; else s+='0'; x/=2; } while(s.size()<60) s+='0'; return s; } ll fb(string s) { ll x = 0; ll c = 1; for(int8_t i = 0 ; 60>i ; i++) { if(s[i]=='1') x+=c; c*=2; } return x; } ll seg[800009]; ll a[200009]; void sb(ll n , ll l , ll r) { if(l==r) { seg[n]=a[l]; return; } sb(2*n,l,mid); sb(2*n+1,mid+1,r); seg[n]=max(seg[2*n],seg[2*n+1]); } ll sg(ll n , ll l , ll r , ll l1 , ll r1) { if(l>r1||r<l1) return -1e18; if(l>=l1&&r<=r1) return seg[n]; return max(sg(2*n,l,mid,l1,r1),sg(2*n+1,mid+1,r,l1,r1)); } int main() { d3 ll n1; cin >> n1; ll a1[n1+1]; for(int i = 1 ; n1>=i ; i++) cin >> a1[i]; ll q; cin >> q; while(q--) { ll l , r; cin >> l >> r; ll n = r-l+1; for(int i = 1 ; n>=i ; i++) a[i]=a1[i+l-1]; memset(seg,0,sizeof(seg)); sb(1,1,n); pll p[n+1]; pll s[n+1]; ll mx = -1e18; ll idx = 0; for(int i = 1 ; n>=i ; i++) { if(a[i]>=mx) { mx=a[i]; idx=i; } p[i].F=mx; p[i].S=idx; } mx = -1e18; idx = 0; for(int i = n ; i>0 ; i--) { if(a[i]>mx) { mx=a[i]; idx=i; } s[i].F=mx; s[i].S=idx; } ll ans = -1e18; for(int i = 2 ; n>i ; i++) { ll x = p[i-1].F; ll idx = p[i-1].S; ll y = s[i+1].F; ll idy = s[i+1].S; ll ans1 = -1e18 , ans2 = -1e18; if(2*i-idx<=n) ans1 = x+a[i]+s[2*i-idx].F; ll w = 1; ans2 = sg(1,1,n,max(2*i-idy,w),i-1)+a[i]+y; ans=max(ans,max(ans1,ans2)); } cans } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...