Submission #963783

# Submission time Handle Problem Language Result Execution time Memory
963783 2024-04-15T16:45:58 Z EJIC_B_KEDAX Snowball (JOI21_ho_t2) C++17
0 / 100
1 ms 2392 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++) {
        int 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];
            int l = -1, r = q + 1;
            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];
            int l = -1, r = q + 1;
            while (r - l > 1) {
                int m = (r + l) / 2;
                if (mx[m] - mn[m] >= dist) {
                    r = m;
                } else {
                    l = m;
                }
            }
            if (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 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -