Submission #963792

# Submission time Handle Problem Language Result Execution time Memory
963792 2024-04-15T16:56:11 Z EJIC_B_KEDAX Snowball (JOI21_ho_t2) C++17
100 / 100
111 ms 15440 KB
#ifdef LOCAL
    #define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>

#ifndef LOCAL
    // #pragma GCC optimize("O3")
    // #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    #pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt")
#endif
using namespace std;
using ll = long long;
using ld = long double;
#define x first
#define y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

mt19937 mt(123);

void solve();
void init();

int32_t main() {
#ifndef LOCAL
    cin.tie(nullptr)->sync_with_stdio(false);
#endif
    cout << fixed << setprecision(30);
    init();
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}

void init() {}

const int N = 200200;
ll x[N], w[N], mn[N], mx[N], ans[N];

void solve() {
    int n, q;
    cin >> n >> q;
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    for (int i = 0; i < q; i++) {
        ll nw;
        cin >> nw;
        w[i + 1] = w[i] + nw;
    }
    for (int i = 1; i <= q; i++) {
        mn[i] = min(mn[i - 1], w[i]);
        mx[i] = max(mx[i - 1], w[i]);
    }
    for (int i = 0; i < n; i++) {
        if (i) {
            ll dist = x[i] - x[i - 1];
            if (dist >= mx[q] - mn[q]) {
                ans[i] -= mn[q];
            } else {
                int l = 0, r = q;
                while (r - l > 1) {
                    int m = (r + l) / 2;
                    if (mx[m] - mn[m] >= dist) {
                        r = m;
                    } else {
                        l = m;
                    }
                }
                if (mx[r] != mx[l]) {
                    ans[i] -= mn[r];
                } else {
                    ans[i] += dist - mx[r];
                }
            }
        } else {
            ans[i] -= mn[q];
        }
        if (i + 1 < n) {
            ll dist = x[i + 1] - x[i];
            if (dist >= mx[q] - mn[q]) {
                ans[i] += mx[q];
            } else {
                int l = 0, r = q;
                while (r - l > 1) {
                    int m = (r + l) / 2;
                    if (mx[m] - mn[m] >= dist) {
                        r = m;
                    } else {
                        l = m;
                    }
                }
                if (r == q + 1 || mn[r] != mn[l]) {
                    ans[i] += mx[r];
                } else {
                    ans[i] += dist + mn[r];
                }
            }
        } else {
            ans[i] += mx[q];
        }
    }
    for (int i = 0; i < n; i++) {
        cout << ans[i] << '\n';
    }
} 
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 392 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2648 KB Output is correct
16 Correct 1 ms 608 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 392 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2648 KB Output is correct
16 Correct 1 ms 608 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 23 ms 7252 KB Output is correct
21 Correct 24 ms 7108 KB Output is correct
22 Correct 19 ms 6872 KB Output is correct
23 Correct 18 ms 6736 KB Output is correct
24 Correct 27 ms 7260 KB Output is correct
25 Correct 92 ms 13396 KB Output is correct
26 Correct 111 ms 13504 KB Output is correct
27 Correct 93 ms 13100 KB Output is correct
28 Correct 95 ms 13144 KB Output is correct
29 Correct 95 ms 12804 KB Output is correct
30 Correct 89 ms 12184 KB Output is correct
31 Correct 70 ms 11600 KB Output is correct
32 Correct 41 ms 11604 KB Output is correct
33 Correct 11 ms 3680 KB Output is correct
34 Correct 96 ms 13804 KB Output is correct
35 Correct 93 ms 13136 KB Output is correct
36 Correct 101 ms 13396 KB Output is correct
37 Correct 96 ms 13268 KB Output is correct
38 Correct 101 ms 13136 KB Output is correct
39 Correct 90 ms 13364 KB Output is correct
40 Correct 80 ms 13180 KB Output is correct
41 Correct 21 ms 7840 KB Output is correct
42 Correct 45 ms 11740 KB Output is correct
43 Correct 80 ms 14940 KB Output is correct
44 Correct 27 ms 7768 KB Output is correct
45 Correct 44 ms 13140 KB Output is correct
46 Correct 80 ms 15184 KB Output is correct
47 Correct 85 ms 15260 KB Output is correct
48 Correct 89 ms 15440 KB Output is correct