Submission #593097

# Submission time Handle Problem Language Result Execution time Memory
593097 2022-07-10T11:43:03 Z piOOE Snowball (JOI21_ho_t2) C++17
100 / 100
1173 ms 18540 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q;
    cin >> n >> q;
    vector<ll> x(n), w(q), mx(q), mn(q);
    vector<pair<ll, int>> p(q);
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
    }
    ll sum = 0;
    for (int i = 0; i < q; ++i) {
        cin >> w[i];
        sum += w[i];
        mx[i] = max(i == 0 ? 0 : mx[i - 1], sum);
        mn[i] = min(i == 0 ? 0 : mn[i - 1], sum);
        p[i] = {sum, i};
    }
    sort(p.begin(), p.end());
    vector<int> pref(q), suf(q);
    for (int i = 0; i < q; ++i) {
        pref[i] = min(i == 0 ? q : pref[i - 1], p[i].second);
    }
    for (int i = q - 1; i > -1; --i) {
        suf[i] = min(i == q - 1 ? q : suf[i + 1], p[i].second);
    }
    auto find = [&](ll val) {
        if (val < 0) {
            return upper_bound(p.begin(), p.end(), pair(val, q)) - p.begin() - 1;
        } else {
            return lower_bound(p.begin(), p.end(), pair(val, -1)) - p.begin();
        }
    };
    for (int i = 0; i < n; ++i) {
        ll L, R;
        if (i == 0) {
            L = -mn[q - 1];
        } else {
            ll l = 0, r = x[i] - x[i - 1] + 1;
            while (l + 1 < r) {
                ll mid = (l + r) >> 1;
                int j = find(-mid);
                if (j == -1) {
                    r = mid;
                    continue;
                }
                int id = pref[j];
                if (id == 0 || mx[id - 1] + mid <= x[i] - x[i - 1]) {
                    l = mid;
                } else {
                    r = mid;
                }
            }
            L = l;
        }
        if (i == n - 1) {
            R = mx[q - 1];
        } else {
            ll l = 0, r = x[i + 1] - x[i] + 1;
            while (l + 1 < r) {
                ll mid = (l + r) >> 1;
                int j = find(mid);
                if (j == q) {
                    r = mid;
                    continue;
                }
                int id = suf[j];
                if (id == 0 || -mn[id - 1] + mid <= x[i + 1] - x[i]) {
                    l = mid;
                } else {
                    r = mid;
                }
            }
            R = l;
        }
        cout << L + R << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 6 ms 340 KB Output is correct
5 Correct 5 ms 340 KB Output is correct
6 Correct 4 ms 340 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 4 ms 340 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 6 ms 460 KB Output is correct
16 Correct 5 ms 480 KB Output is correct
17 Correct 4 ms 468 KB Output is correct
18 Correct 0 ms 328 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 6 ms 340 KB Output is correct
5 Correct 5 ms 340 KB Output is correct
6 Correct 4 ms 340 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 4 ms 340 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 6 ms 460 KB Output is correct
16 Correct 5 ms 480 KB Output is correct
17 Correct 4 ms 468 KB Output is correct
18 Correct 0 ms 328 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 41 ms 11944 KB Output is correct
21 Correct 41 ms 11732 KB Output is correct
22 Correct 41 ms 11352 KB Output is correct
23 Correct 51 ms 11280 KB Output is correct
24 Correct 160 ms 11652 KB Output is correct
25 Correct 1153 ms 16612 KB Output is correct
26 Correct 1134 ms 16516 KB Output is correct
27 Correct 1173 ms 16228 KB Output is correct
28 Correct 1093 ms 16348 KB Output is correct
29 Correct 1039 ms 15856 KB Output is correct
30 Correct 565 ms 15364 KB Output is correct
31 Correct 100 ms 14608 KB Output is correct
32 Correct 76 ms 14748 KB Output is correct
33 Correct 70 ms 2004 KB Output is correct
34 Correct 1008 ms 17060 KB Output is correct
35 Correct 1074 ms 16284 KB Output is correct
36 Correct 1152 ms 16564 KB Output is correct
37 Correct 1089 ms 16396 KB Output is correct
38 Correct 1075 ms 16216 KB Output is correct
39 Correct 1034 ms 16532 KB Output is correct
40 Correct 433 ms 16372 KB Output is correct
41 Correct 35 ms 12368 KB Output is correct
42 Correct 164 ms 14824 KB Output is correct
43 Correct 292 ms 18036 KB Output is correct
44 Correct 39 ms 12232 KB Output is correct
45 Correct 517 ms 16356 KB Output is correct
46 Correct 332 ms 18160 KB Output is correct
47 Correct 331 ms 18508 KB Output is correct
48 Correct 328 ms 18540 KB Output is correct