Submission #944024

# Submission time Handle Problem Language Result Execution time Memory
944024 2024-03-12T06:51:08 Z beepbeepsheep Triple Jump (JOI19_jumps) C++17
0 / 100
186 ms 27216 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ii pair<ll,ll>
#ifndef DEBUG
#define cerr if (0) cerr
#define endl '\n'
#endif

const ll maxn=2e5+5;
const ll inf=1e15;
ll arr[maxn];
struct node{
    ll s,e,m,val;
    node *l,*r;
    node (ll _s, ll _e){
        s=_s,e=_e,m=(s+e)>>1,val=0;
        if (s!=e) l=new node(s,m),r=new node(m+1,e);
    }
    void upd(ll x, ll v){
        if (s==e){
            val=v;
            return;
        }
        if (x>m) r->upd(x,v);
        else l->upd(x,v);
        val=max(l->val,r->val);
    }
    ll query(ll x, ll y){
        if (x<=s && e<=y) return val;
        if (x>m) return r->query(x,y);
        if (y<=m) return l->query(x,y);
        return max(l->query(x,y),r->query(x,y));
    }
}*root;

ll ans=0;
ll n;
void dnc(ll l, ll r,ll optl, ll optr){
    //cerr<<l<<' '<<r<<' '<<optl<<' '<<optr<<endl;
    if (l>r) return;
    ll m=(l+r)>>1;
    ll opt=-1,best=0;
    for (int i=optl;i<=min(m-1,optr);i++){
        ll res=arr[i]+root->query(m+1,min(2*m-i,n));
        if (res>best){
            opt=i;
            best=res;
        }
    }
    ans=max(ans,best+arr[m]);
    dnc(l,m-1,optl,opt);
    dnc(m+1,r,opt,optr);
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    root=new node(1,n);
    for (int i=1;i<=n;i++) cin>>arr[i],root->upd(i,arr[i]);
    ll q,l,r;
    cin>>q;
    assert(q==1);
    cin>>l>>r;
    assert(l==1 && r==n);
    dnc(2,n-1,1,n);
    cout<<ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Runtime error 1 ms 604 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Runtime error 1 ms 604 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 186 ms 27216 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Runtime error 1 ms 604 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -