Submission #593094

# Submission time Handle Problem Language Result Execution time Memory
593094 2022-07-10T11:36:15 Z piOOE Snowball (JOI21_ho_t2) C++17
0 / 100
6 ms 560 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();
        }
    };
    const ll inf = 3e12;
    for (int i = 0; i < n; ++i) {
        ll L, R;
        if (i == 0) {
            L = -mn[q - 1];
        } else {
            ll l = 0, r = inf;
            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 = inf;
            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 << ' ';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 560 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 5 ms 460 KB Output is correct
5 Correct 6 ms 468 KB Output is correct
6 Correct 5 ms 468 KB Output is correct
7 Correct 4 ms 464 KB Output is correct
8 Correct 4 ms 468 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Incorrect 1 ms 340 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 560 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 5 ms 460 KB Output is correct
5 Correct 6 ms 468 KB Output is correct
6 Correct 5 ms 468 KB Output is correct
7 Correct 4 ms 464 KB Output is correct
8 Correct 4 ms 468 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Incorrect 1 ms 340 KB Output isn't correct
15 Halted 0 ms 0 KB -