답안 #613959

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
613959 2022-07-30T14:39:10 Z AmirElarbi 3단 점프 (JOI19_jumps) C++14
0 / 100
69 ms 4900 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;
        int res = 0;
        for (int i = 0; i < mx.se; ++i)
        {
            if(i == mx.se) continue;
            int dst = abs(mx.se-i);
            int 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);
            int cur = query(1, 0,n-1, i+dst, n-1);
            if(cur != -1) res = max(cur+s[i]+mx.fi, res);
        }
        cout << res << endl;
    }
}


# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 4808 KB Output is correct
2 Correct 69 ms 4820 KB Output is correct
3 Correct 32 ms 4820 KB Output is correct
4 Incorrect 34 ms 4900 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -