Submission #811568

#TimeUsernameProblemLanguageResultExecution timeMemory
811568vjudge1Triple Jump (JOI19_jumps)C++17
19 / 100
4059 ms323284 KiB


#include <bits/stdc++.h>



using namespace std;

#define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define rall(s) s.rbegin(),s.rend()
#define all(s) s.begin(),s.end()
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define yes cout<<"yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define no cout<<"no\n"


const int N = 5e5 + 9 , mod = 1e9 + 7;
ll  d[N] = {} , a[N] = {}, dp[5009][5009] ,  b[N] , c[5009][5009] = {} , tree[2 * N];


void build(int i , int l , int r){
    if(l == r){
        tree[i] = a[l];
        return;
    }
    ll m = (l + r) / 2;
    build(i * 2 , l , m);
    build(i * 2  + 1, m + 1 , r);
    tree[i] = max(tree[2 * i] , tree[2 * i + 1]);
}

ll get(int i , int l , int r, int x , int y){
    if(l > y || r < x)
        return 0;
    if(l >= x && r  <= y)
        return tree[i];
    ll m = (l + r) / 2;
    return max(get(2 * i , l , m ,x , y) , get(2 * i +  1 , m + 1 , r,x , y));
}


void solve(){
    ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
    cin>>n;
    for(i = 1; i <= n; i++)
        cin>>a[i];
    build(1 , 1 , n);
    for(i = 1; i <= n; i++)
        for(j = i + 2; j <= n; j++)
            l = i + 1, r = i + (j - i) / 2 , c[i][j] = max(c[i][j - 1], get(1 , 1 , n , l , r) + a[i] + a[j]);
    for(i = n; i >= 1; i--)
        for(j = n; j >= 1; j--)
            dp[i][j] = max({c[i][j] ,dp[i + 1][j]});
    cin>>q;
    while(q--){
        cin>>l>>r;
        cout<<dp[l][r]<<"\n";
    }
}

int main(){

    /* TL;
     #ifndef ONLINE_JUDGE
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
     #endif
     */
int t = 1;
//cin>>t;

while(t--)
     {
     solve();
     }

}
// Author : حسن

Compilation message (stderr)

jumps.cpp: In function 'void solve()':
jumps.cpp:51:20: warning: unused variable 'm' [-Wunused-variable]
   51 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                    ^
jumps.cpp:51:26: warning: unused variable 'z' [-Wunused-variable]
   51 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                          ^
jumps.cpp:51:29: warning: unused variable 's' [-Wunused-variable]
   51 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                             ^
jumps.cpp:51:37: warning: unused variable 'f' [-Wunused-variable]
   51 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                     ^
jumps.cpp:51:49: warning: unused variable 'k' [-Wunused-variable]
   51 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                                 ^
jumps.cpp:51:53: warning: unused variable 'x' [-Wunused-variable]
   51 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                                     ^
jumps.cpp:51:57: warning: unused variable 'y' [-Wunused-variable]
   51 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                                         ^
jumps.cpp:51:61: warning: unused variable 'mn' [-Wunused-variable]
   51 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                                             ^~
jumps.cpp:51:74: warning: unused variable 'mx' [-Wunused-variable]
   51 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                                                          ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...