Submission #426285

# Submission time Handle Problem Language Result Execution time Memory
426285 2021-06-13T16:51:06 Z timmyfeng Shortcut (IOI16_shortcut) C++17
0 / 100
1 ms 332 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1000001;

long long fenw[N][2], sum[N], diff[N], x[N];
int sum_order[N], diff_order[N], n;

array<long long, 2> query(int a) {
    long long min_ans = LLONG_MAX, max_ans = LLONG_MIN;
    for ( ; a > 0; a -= a & -a) {
        min_ans = min(min_ans, fenw[a][0]);
        max_ans = max(max_ans, fenw[a][1]);
    }
    return {min_ans, max_ans};
}

void update(int a, long long x, long long y) {
    for ( ; a <= n; a += a & -a) {
        fenw[a][0] = min(fenw[a][0], x);
        fenw[a][1] = max(fenw[a][1], y);
    }
}

long long find_shortcut(int n, vector<int> l, vector<int> d, int c) {
    ::n = n;

    for (int i = 0; i < n - 1; ++i) {
        x[i + 1] = x[i] + l[i];
    }

    for (int i = 0; i < n; ++i) {
        sum[i] = x[i] + d[i];
        diff[i] = x[i] - d[i];
    }

    iota(sum_order, sum_order + n, 0);
    sort(sum_order, sum_order + n, [&](int a, int b) {
        return sum[a] < sum[b];
    });

    iota(diff_order, diff_order + n, 0);
    sort(diff_order, diff_order + n, [&](int a, int b) {
        return diff[a] < diff[b];
    });

    long long low = 0, high = sum[sum_order[n - 1]] - diff[diff_order[0]];
    while (low < high) {
        long long mid = (low + high) / 2;

        long long min_sum = LLONG_MIN, max_sum = LLONG_MAX;
        long long min_diff = LLONG_MIN, max_diff = LLONG_MAX;

        for (int i = 0; i < n; ++i) {
            fenw[i][0] = LLONG_MAX;
            fenw[i][1] = LLONG_MIN;
        }

        for (int i = 0, j = 0; j < n; ++j) {
            while (i < n && sum[sum_order[j]] - diff[diff_order[i]] > mid) {
                update(diff_order[i] + 1, diff[diff_order[i]], sum[diff_order[i]]);
                ++i;
            }

            auto [min_i, max_i] = query(sum_order[j]);
            if (min_i < LLONG_MAX) {
                min_sum = max(min_sum, -mid + c + sum[sum_order[j]] + max_i);
                max_sum = min(max_sum, mid - c + diff[sum_order[j]] + min_i);
                min_diff = max(min_diff, -mid + c + sum[sum_order[j]] - min_i);
                max_diff = min(max_diff, mid - c + diff[sum_order[j]] - max_i);
            }
        }

        if (min_sum <= max_sum && min_diff <= max_diff) {
            high = mid;
        } else {
            low = mid + 1;
        }
    }

    return low;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB n = 4, 80 is a correct answer
2 Correct 1 ms 332 KB n = 9, 110 is a correct answer
3 Correct 0 ms 332 KB n = 4, 21 is a correct answer
4 Correct 0 ms 288 KB n = 3, 4 is a correct answer
5 Correct 1 ms 332 KB n = 2, 62 is a correct answer
6 Correct 1 ms 332 KB n = 2, 3 is a correct answer
7 Correct 1 ms 332 KB n = 3, 29 is a correct answer
8 Correct 1 ms 332 KB n = 2, 3 is a correct answer
9 Correct 1 ms 332 KB n = 2, 3 is a correct answer
10 Correct 1 ms 332 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 332 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 332 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 332 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 332 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 332 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 332 KB n = 5, 4000000000 is a correct answer
17 Incorrect 1 ms 332 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000317
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB n = 4, 80 is a correct answer
2 Correct 1 ms 332 KB n = 9, 110 is a correct answer
3 Correct 0 ms 332 KB n = 4, 21 is a correct answer
4 Correct 0 ms 288 KB n = 3, 4 is a correct answer
5 Correct 1 ms 332 KB n = 2, 62 is a correct answer
6 Correct 1 ms 332 KB n = 2, 3 is a correct answer
7 Correct 1 ms 332 KB n = 3, 29 is a correct answer
8 Correct 1 ms 332 KB n = 2, 3 is a correct answer
9 Correct 1 ms 332 KB n = 2, 3 is a correct answer
10 Correct 1 ms 332 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 332 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 332 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 332 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 332 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 332 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 332 KB n = 5, 4000000000 is a correct answer
17 Incorrect 1 ms 332 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000317
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB n = 4, 80 is a correct answer
2 Correct 1 ms 332 KB n = 9, 110 is a correct answer
3 Correct 0 ms 332 KB n = 4, 21 is a correct answer
4 Correct 0 ms 288 KB n = 3, 4 is a correct answer
5 Correct 1 ms 332 KB n = 2, 62 is a correct answer
6 Correct 1 ms 332 KB n = 2, 3 is a correct answer
7 Correct 1 ms 332 KB n = 3, 29 is a correct answer
8 Correct 1 ms 332 KB n = 2, 3 is a correct answer
9 Correct 1 ms 332 KB n = 2, 3 is a correct answer
10 Correct 1 ms 332 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 332 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 332 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 332 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 332 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 332 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 332 KB n = 5, 4000000000 is a correct answer
17 Incorrect 1 ms 332 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000317
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB n = 4, 80 is a correct answer
2 Correct 1 ms 332 KB n = 9, 110 is a correct answer
3 Correct 0 ms 332 KB n = 4, 21 is a correct answer
4 Correct 0 ms 288 KB n = 3, 4 is a correct answer
5 Correct 1 ms 332 KB n = 2, 62 is a correct answer
6 Correct 1 ms 332 KB n = 2, 3 is a correct answer
7 Correct 1 ms 332 KB n = 3, 29 is a correct answer
8 Correct 1 ms 332 KB n = 2, 3 is a correct answer
9 Correct 1 ms 332 KB n = 2, 3 is a correct answer
10 Correct 1 ms 332 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 332 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 332 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 332 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 332 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 332 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 332 KB n = 5, 4000000000 is a correct answer
17 Incorrect 1 ms 332 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000317
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB n = 4, 80 is a correct answer
2 Correct 1 ms 332 KB n = 9, 110 is a correct answer
3 Correct 0 ms 332 KB n = 4, 21 is a correct answer
4 Correct 0 ms 288 KB n = 3, 4 is a correct answer
5 Correct 1 ms 332 KB n = 2, 62 is a correct answer
6 Correct 1 ms 332 KB n = 2, 3 is a correct answer
7 Correct 1 ms 332 KB n = 3, 29 is a correct answer
8 Correct 1 ms 332 KB n = 2, 3 is a correct answer
9 Correct 1 ms 332 KB n = 2, 3 is a correct answer
10 Correct 1 ms 332 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 332 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 332 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 332 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 332 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 332 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 332 KB n = 5, 4000000000 is a correct answer
17 Incorrect 1 ms 332 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000317
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB n = 4, 80 is a correct answer
2 Correct 1 ms 332 KB n = 9, 110 is a correct answer
3 Correct 0 ms 332 KB n = 4, 21 is a correct answer
4 Correct 0 ms 288 KB n = 3, 4 is a correct answer
5 Correct 1 ms 332 KB n = 2, 62 is a correct answer
6 Correct 1 ms 332 KB n = 2, 3 is a correct answer
7 Correct 1 ms 332 KB n = 3, 29 is a correct answer
8 Correct 1 ms 332 KB n = 2, 3 is a correct answer
9 Correct 1 ms 332 KB n = 2, 3 is a correct answer
10 Correct 1 ms 332 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 332 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 332 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 332 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 332 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 332 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 332 KB n = 5, 4000000000 is a correct answer
17 Incorrect 1 ms 332 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000317
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB n = 4, 80 is a correct answer
2 Correct 1 ms 332 KB n = 9, 110 is a correct answer
3 Correct 0 ms 332 KB n = 4, 21 is a correct answer
4 Correct 0 ms 288 KB n = 3, 4 is a correct answer
5 Correct 1 ms 332 KB n = 2, 62 is a correct answer
6 Correct 1 ms 332 KB n = 2, 3 is a correct answer
7 Correct 1 ms 332 KB n = 3, 29 is a correct answer
8 Correct 1 ms 332 KB n = 2, 3 is a correct answer
9 Correct 1 ms 332 KB n = 2, 3 is a correct answer
10 Correct 1 ms 332 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 332 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 332 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 332 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 332 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 332 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 332 KB n = 5, 4000000000 is a correct answer
17 Incorrect 1 ms 332 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000317
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB n = 4, 80 is a correct answer
2 Correct 1 ms 332 KB n = 9, 110 is a correct answer
3 Correct 0 ms 332 KB n = 4, 21 is a correct answer
4 Correct 0 ms 288 KB n = 3, 4 is a correct answer
5 Correct 1 ms 332 KB n = 2, 62 is a correct answer
6 Correct 1 ms 332 KB n = 2, 3 is a correct answer
7 Correct 1 ms 332 KB n = 3, 29 is a correct answer
8 Correct 1 ms 332 KB n = 2, 3 is a correct answer
9 Correct 1 ms 332 KB n = 2, 3 is a correct answer
10 Correct 1 ms 332 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 332 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 332 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 332 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 332 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 332 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 332 KB n = 5, 4000000000 is a correct answer
17 Incorrect 1 ms 332 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000317
18 Halted 0 ms 0 KB -