답안 #370970

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
370970 2021-02-25T09:57:08 Z dolphingarlic Shortcut (IOI16_shortcut) C++14
0 / 100
1 ms 364 KB
#include "shortcut.h"

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const ll INF = 1e16;

void update(vector<ll> &segtree, int pos, ll val, int node, int l, int r) {
    if (l == r) segtree[node] = val;
    else {
        int mid = (l + r) / 2;
        if (pos > mid) update(segtree, pos, val, node * 2 + 1, mid + 1, r);
        else update(segtree, pos, val, node * 2, l, mid);
        segtree[node] = max(segtree[node * 2], segtree[node * 2 + 1]);
    }
}

ll query(vector<ll> &segtree, int a, int b, int node, int l, int r) {
    if (a > b || l > b || r < a) return -INF;
    if (l >= a && r <= b) return segtree[node];
    int mid = (l + r) / 2;
    return max(query(segtree, a, b, node * 2, l, mid), query(segtree, a, b, node * 2 + 1, mid + 1, r));
}

ll find_shortcut(int n, vector<int> l, vector<int> d, int c) {
    vector<ll> p(n, 0);
    for (int i = 1; i < n; i++) p[i] = p[i - 1] + l[i - 1];

    // Order the stations by their inequality stuff
    vector<pair<ll, int>> iot(n);
    vector<int> ord(n);
    // Order by d[i] + p[i]
    for (int i = 0; i < n; i++) iot[i] = {d[i] + p[i], i};
    sort(iot.begin(), iot.end());
    for (int i = 0; i < n; i++) ord[iot[i].second] = i;

    // A segtree for each inequality
    vector<ll> seg[2];
    for (int i : {0, 1}) seg[i].resize(4 * n);

    // Binary search for the answer
    ll lo = 0, hi = INF;
    while (lo != hi) {
        ll mid = (lo + hi) / 2;
        // Reset the segtrees
        for (int i : {0, 1}) fill(seg[i].begin(), seg[i].end(), -INF);

        vector<ll> half_plane(4, -INF);
        for (int i = n - 1; ~i; i--) {
            // Get the index of the first non-ignored station
            int threshold = upper_bound(iot.begin(), iot.end(), make_pair(mid - d[i] + p[i], n)) - iot.begin();
            // Update the half planes
            half_plane[0] = max(half_plane[0], c - mid + d[i] + p[i] + query(seg[0], threshold, n - 1, 1, 0, n - 1));
            half_plane[1] = max(half_plane[1], c - mid + d[i] - p[i] + query(seg[0], threshold, n - 1, 1, 0, n - 1));
            half_plane[2] = max(half_plane[2], c - mid + d[i] + p[i] + query(seg[1], threshold, n - 1, 1, 0, n - 1));
            half_plane[3] = max(half_plane[3], c - mid + d[i] - p[i] + query(seg[1], threshold, n - 1, 1, 0, n - 1));
            // Then add station i to the segtrees
            update(seg[0], ord[i], d[i] + p[i], 1, 0, n - 1);
            update(seg[1], ord[i], d[i] - p[i], 1, 0, n - 1);
        }
        // Check that the half-planes have a common intersection
        if (half_plane[0] <= -half_plane[3] && half_plane[1] <= -half_plane[2]) hi = mid;
        else lo = mid + 1;
    }
    return lo;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n = 4, 80 is a correct answer
2 Correct 1 ms 364 KB n = 9, 110 is a correct answer
3 Correct 1 ms 364 KB n = 4, 21 is a correct answer
4 Correct 1 ms 364 KB n = 3, 4 is a correct answer
5 Correct 1 ms 364 KB n = 2, 62 is a correct answer
6 Correct 1 ms 364 KB n = 2, 3 is a correct answer
7 Correct 1 ms 364 KB n = 3, 29 is a correct answer
8 Correct 1 ms 364 KB n = 2, 3 is a correct answer
9 Correct 1 ms 364 KB n = 2, 3 is a correct answer
10 Correct 1 ms 364 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 364 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 364 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 364 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 364 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 364 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 364 KB n = 5, 4000000000 is a correct answer
17 Incorrect 1 ms 364 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000317
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n = 4, 80 is a correct answer
2 Correct 1 ms 364 KB n = 9, 110 is a correct answer
3 Correct 1 ms 364 KB n = 4, 21 is a correct answer
4 Correct 1 ms 364 KB n = 3, 4 is a correct answer
5 Correct 1 ms 364 KB n = 2, 62 is a correct answer
6 Correct 1 ms 364 KB n = 2, 3 is a correct answer
7 Correct 1 ms 364 KB n = 3, 29 is a correct answer
8 Correct 1 ms 364 KB n = 2, 3 is a correct answer
9 Correct 1 ms 364 KB n = 2, 3 is a correct answer
10 Correct 1 ms 364 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 364 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 364 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 364 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 364 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 364 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 364 KB n = 5, 4000000000 is a correct answer
17 Incorrect 1 ms 364 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000317
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n = 4, 80 is a correct answer
2 Correct 1 ms 364 KB n = 9, 110 is a correct answer
3 Correct 1 ms 364 KB n = 4, 21 is a correct answer
4 Correct 1 ms 364 KB n = 3, 4 is a correct answer
5 Correct 1 ms 364 KB n = 2, 62 is a correct answer
6 Correct 1 ms 364 KB n = 2, 3 is a correct answer
7 Correct 1 ms 364 KB n = 3, 29 is a correct answer
8 Correct 1 ms 364 KB n = 2, 3 is a correct answer
9 Correct 1 ms 364 KB n = 2, 3 is a correct answer
10 Correct 1 ms 364 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 364 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 364 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 364 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 364 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 364 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 364 KB n = 5, 4000000000 is a correct answer
17 Incorrect 1 ms 364 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000317
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n = 4, 80 is a correct answer
2 Correct 1 ms 364 KB n = 9, 110 is a correct answer
3 Correct 1 ms 364 KB n = 4, 21 is a correct answer
4 Correct 1 ms 364 KB n = 3, 4 is a correct answer
5 Correct 1 ms 364 KB n = 2, 62 is a correct answer
6 Correct 1 ms 364 KB n = 2, 3 is a correct answer
7 Correct 1 ms 364 KB n = 3, 29 is a correct answer
8 Correct 1 ms 364 KB n = 2, 3 is a correct answer
9 Correct 1 ms 364 KB n = 2, 3 is a correct answer
10 Correct 1 ms 364 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 364 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 364 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 364 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 364 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 364 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 364 KB n = 5, 4000000000 is a correct answer
17 Incorrect 1 ms 364 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000317
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n = 4, 80 is a correct answer
2 Correct 1 ms 364 KB n = 9, 110 is a correct answer
3 Correct 1 ms 364 KB n = 4, 21 is a correct answer
4 Correct 1 ms 364 KB n = 3, 4 is a correct answer
5 Correct 1 ms 364 KB n = 2, 62 is a correct answer
6 Correct 1 ms 364 KB n = 2, 3 is a correct answer
7 Correct 1 ms 364 KB n = 3, 29 is a correct answer
8 Correct 1 ms 364 KB n = 2, 3 is a correct answer
9 Correct 1 ms 364 KB n = 2, 3 is a correct answer
10 Correct 1 ms 364 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 364 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 364 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 364 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 364 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 364 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 364 KB n = 5, 4000000000 is a correct answer
17 Incorrect 1 ms 364 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000317
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n = 4, 80 is a correct answer
2 Correct 1 ms 364 KB n = 9, 110 is a correct answer
3 Correct 1 ms 364 KB n = 4, 21 is a correct answer
4 Correct 1 ms 364 KB n = 3, 4 is a correct answer
5 Correct 1 ms 364 KB n = 2, 62 is a correct answer
6 Correct 1 ms 364 KB n = 2, 3 is a correct answer
7 Correct 1 ms 364 KB n = 3, 29 is a correct answer
8 Correct 1 ms 364 KB n = 2, 3 is a correct answer
9 Correct 1 ms 364 KB n = 2, 3 is a correct answer
10 Correct 1 ms 364 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 364 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 364 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 364 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 364 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 364 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 364 KB n = 5, 4000000000 is a correct answer
17 Incorrect 1 ms 364 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000317
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n = 4, 80 is a correct answer
2 Correct 1 ms 364 KB n = 9, 110 is a correct answer
3 Correct 1 ms 364 KB n = 4, 21 is a correct answer
4 Correct 1 ms 364 KB n = 3, 4 is a correct answer
5 Correct 1 ms 364 KB n = 2, 62 is a correct answer
6 Correct 1 ms 364 KB n = 2, 3 is a correct answer
7 Correct 1 ms 364 KB n = 3, 29 is a correct answer
8 Correct 1 ms 364 KB n = 2, 3 is a correct answer
9 Correct 1 ms 364 KB n = 2, 3 is a correct answer
10 Correct 1 ms 364 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 364 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 364 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 364 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 364 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 364 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 364 KB n = 5, 4000000000 is a correct answer
17 Incorrect 1 ms 364 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000317
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n = 4, 80 is a correct answer
2 Correct 1 ms 364 KB n = 9, 110 is a correct answer
3 Correct 1 ms 364 KB n = 4, 21 is a correct answer
4 Correct 1 ms 364 KB n = 3, 4 is a correct answer
5 Correct 1 ms 364 KB n = 2, 62 is a correct answer
6 Correct 1 ms 364 KB n = 2, 3 is a correct answer
7 Correct 1 ms 364 KB n = 3, 29 is a correct answer
8 Correct 1 ms 364 KB n = 2, 3 is a correct answer
9 Correct 1 ms 364 KB n = 2, 3 is a correct answer
10 Correct 1 ms 364 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 364 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 364 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 364 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 364 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 364 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 364 KB n = 5, 4000000000 is a correct answer
17 Incorrect 1 ms 364 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000317
18 Halted 0 ms 0 KB -