답안 #655404

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
655404 2022-11-04T09:31:21 Z piOOE 3단 점프 (JOI19_jumps) C++17
0 / 100
28 ms 14180 KB
#include <bits/stdc++.h>

using namespace std;

constexpr int inf = 1e9 + 7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    auto func = [&](int i, int j) {
        return a[i] > a[j] ? i : j;
    };

    const int max_log = __lg(n) + bool(n & (n - 1));
    vector<vector<int>> st(max_log);
    st[0].resize(n);
    iota(st[0].begin(), st[0].end(), 0);
    for (int i = 1; i < max_log; ++i) {
        st[i].resize(n - (1 << i) + 1);
        for (int j = 0; j < (int) st[i].size(); ++j) {
            st[i][j] = func(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
        }
    }

    auto query = [&](int l, int r) {
        assert(l < r);
        int lg = __lg(r - l);
        return func(st[lg][l], st[lg][r - (1 << lg)]);
    };

    int q;
    cin >> q;
    while (q--) {
        int l, r;
        cin >> l >> r;
        --l;
        vector<int> p;
        priority_queue<array<int, 3>> pq;
        pq.push({a[query(l, r)], l, r});
        for (int t = 1; t <= 20 && !pq.empty(); ++t) {
            auto [val, L, R] = pq.top();
            pq.pop();
            int i = query(L, R);
            p.push_back(i);
            if (L < i) {
                pq.push({a[query(L, i)], L, i});
            }
            if (i + 1 < R) {
                pq.push({a[query(i + 1, R)], i + 1, R});
            }
        }
        int ans = 0;
        for (int i: p) {
            for (int j: p) {
                if (i < j) {
                    int R = j + (j - i);
                    if (R < r) {
                        ans = max(ans, a[i] + a[j] + a[query(R, r)]);
                    }
                    int len = j - i - 1;
                    if (len > 0) {
                        ans = max(ans, a[i] + a[j] + a[query(i + 1, i + 1 + ((len + 1) / 2))]);
                    }
                    int L = max(l, i - (j - i));
                    if (L < i) {
                        ans = max(ans, a[i] + a[j] + a[query(L, i)]);
                    }
                }
            }
        }
        cout << ans << '\n';
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Incorrect 1 ms 212 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Incorrect 1 ms 212 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 14176 KB Output is correct
2 Correct 25 ms 14180 KB Output is correct
3 Correct 28 ms 14152 KB Output is correct
4 Correct 27 ms 14100 KB Output is correct
5 Correct 25 ms 14176 KB Output is correct
6 Incorrect 22 ms 14164 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Incorrect 1 ms 212 KB Output isn't correct
8 Halted 0 ms 0 KB -