Submission #613997

# Submission time Handle Problem Language Result Execution time Memory
613997 2022-07-30T16:02:05 Z AmirElarbi Triple Jump (JOI19_jumps) C++14
0 / 100
73 ms 4932 KB
#include <bits/stdc++.h>
#define vi vector<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 2e9+5
#define eps 1e-7
#define eps1 1e-25
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 1e5+5
#define V 450
using namespace std;
const int MOD = 1e9;
const int nax = 4e5+5;
const int lg = 20;
vi s;
int st[nax*4];
void build(int v, int l, int r){
    if(l == r) {
        st[v] = s[l];
        return;
    }
    int md = (l+r)/2;
    build(v*2, l, md);
    build(v*2+1, md+1, r);
    st[v]  = max(st[v*2], st[v*2+1]);
}
int query(int v, int l, int r, int i, int j){
    if(j < l || i > r) return -1;
    if(i <= l && r <= j) return st[v];
    int md = (l+r)/2;
    return max(query(v*2,l,md,i,j), query(v*2+1, md+1, r, i, j)); 
}
int main() {
    optimise;
    int n;
    cin >> n;
    s.resize(n);
    ii mx = {0,0};
    for (int i = 0; i < n; ++i)
    {
        cin >> s[i];
        if(mx.fi < s[i]) mx = {s[i],i};
    } 
    build(1,0,n-1);
    int q;
    cin >> q;
    while(q--){
        int l, r;
        cin >> l >> r;
        ll res = 0;
        for (int i = 0; i < mx.se; ++i)
        {
            if(i == mx.se) continue;
            int dst = abs(mx.se-i);
            ll cur = max(query(1, 0, n-1, i+1, mx.se-(dst+1)/2), query(1, 0,n-1, mx.se+dst, n-1));
            if(cur != -1) res = max(cur+s[i]+mx.fi, res);
        }
        for (int i = mx.se+1; i < n; ++i)
        {
            if(i == mx.se) continue;
            int dst = abs(mx.se-i);
            ll cur = query(1, 0,n-1, i+dst, n-1);
            if(cur != -1) res = max(cur+s[i]+mx.fi, res);
        }
        cout << res << endl;
    }
}


# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 44 ms 4904 KB Output is correct
2 Correct 73 ms 4932 KB Output is correct
3 Correct 33 ms 4824 KB Output is correct
4 Incorrect 36 ms 4808 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -