답안 #944882

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
944882 2024-03-13T07:18:57 Z thelegendary08 3단 점프 (JOI19_jumps) C++14
0 / 100
304 ms 73212 KB
#include<bits/stdc++.h>
#define f0r(i,n) for(int i = 0;i<n;i++)
#define pb push_back
#define vll vector<long long int>
using namespace std;
typedef long long int ll;
ll mx[21][500005];
ll maxq(int x, int y){
    if(x <0 || y < 0 || x > y)return -1;
    int len = y - x + 1;
    int num = floor(log2(len));
    return max(mx[num][x], mx[num][y - (int)pow(2,num) + 1]);
}
int main(){
    ll n;
    cin>>n;
    vll v(n);
    f0r(i,n)cin>>v[i];
    int lg = floor(log2(n));

    f0r(i, n){
        mx[0][i] = v[i];
    }
    for(int i = 1;i<=lg;i++){
        f0r(j, n - pow(2, i) + 1){
            mx[i][j] = max(mx[i-1][j], mx[i-1][j + (int)pow(2, i-1)]);
        }
    }/*
    f0r(i,lg+1){
        f0r(j, n)cout<<mx[i][j]<<' ';
        cout<<'\n';
    }
    */

    int q;
    cin>>q;
    while(q--){
        int l,r;
        cin>>l>>r;
        l--;
        r--;
        int sz = r - l + 1;
        int num = floor(log2(sz));
        vector<pair<ll,ll>> w;
        for(int i = l;i<=r;i++)w.pb({v[i], i});
        sort(w.rbegin(), w.rend());
        ll ans = 0;
        f0r(ii, num + 1){
            int i = w[ii].second;
            //i at front
            for(int j = i+1;j<=i + (r-i)/2; j++){
                //range: j + j-i to r.
                //cout<<maxq(j+j-i, r)<<' '<<w[ii].first<<' '<<v[j]<<'\n';
                ans = max(ans, maxq(j+j-i, r) + w[ii].first + v[j]);
            }
            //i at back
            for(int j = i-1;j>=i-(i-l)/2;j--){
                //cout<<j-(i-j)<<' '<<j-1<<' '<<maxq(j-(i - j), j-1)<<'\n';
                //cout<<maxq(j-(i - j), j-1)<<' '<<w[ii].first<<' '<<v[j]<<'\n';
                ans = max(ans, maxq(j-(i - j), j-1) + w[ii].first + v[j]);
            }
            //i in middle
            for(int j = i+1;j<=i+min(r-i,i-l);j++){
                //cout<<maxq(i-(j-i),i-1)<<' '<<w[ii].first<<' '<<v[j]<<'\n';
                ans = max(ans, maxq(i-(j-i),i-1) + w[ii].first + v[j]);
            }
        }
        cout<<ans<<'\n';

        /*
        f0r(i,  num - 1){
            for(int j = i+1;j<num;j++){
                for(int k = j+1;k<num+1;k++){
                    vll temp = {w[i].second, w[j].second, w[k].second};
                    sort(temp.begin(), temp.end());
                    if(temp[1] - temp[0] <= temp[2]- temp[1]){
                        ans = max(ans, w[i].first + w[j].first + w[k].first);
                    }
                }
            }
        }
        */

    }

}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 2 ms 12636 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 2 ms 12636 KB Output is correct
5 Correct 2 ms 12636 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Incorrect 2 ms 12636 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 2 ms 12636 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 2 ms 12636 KB Output is correct
5 Correct 2 ms 12636 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Incorrect 2 ms 12636 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 304 ms 71668 KB Output is correct
2 Correct 234 ms 71980 KB Output is correct
3 Correct 237 ms 72380 KB Output is correct
4 Correct 256 ms 73212 KB Output is correct
5 Correct 255 ms 72384 KB Output is correct
6 Incorrect 259 ms 70956 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 2 ms 12636 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 2 ms 12636 KB Output is correct
5 Correct 2 ms 12636 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Incorrect 2 ms 12636 KB Output isn't correct
8 Halted 0 ms 0 KB -