Submission #378360

#TimeUsernameProblemLanguageResultExecution timeMemory
378360smjleoSnowball (JOI21_ho_t2)C++14
100 / 100
116 ms11216 KiB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define int long long
#define nl '\n'
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
mt19937 rng((unsigned)chrono::steady_clock::now().time_since_epoch().count());
const int mod = 1000000007, mod2 = 998244353;

// change this
const int N = 200005;

int n, q, x[N], w, ans[N];

signed main() {
    io;
    // cout << "COMPILED" << endl;
    cin >> n >> q;
    vector< pair<int, pair<int, int> > > inter;
    for (int i=0; i<n; i++) {
        cin >> x[i];
        if (i) inter.push_back({x[i] - x[i-1], {i-1, i}});
    }

    sort(inter.begin(), inter.end());
    int l = 0, r = 0, d = 0, j = 0, m = inter.size();

    for (int i=0; i<q; i++) {
        cin >> w;
        d += w;
        int lo = l, ro = r; // old ones before we change
        l = max(l, -d), r = max(r, d);
        // cout << l << ' ' << r << endl;
        // we can move at most r to the right and at most l to the left
        
        while (j < m && inter[j].first < l + r) {
            // this interval exceeds movement
            // ok lets handle this
            if (r > ro) {
                // r increased
                // cout << inter[j].second.first << ' ' << inter[j].first - lo << ' ' << lo << endl;
                ans[inter[j].second.second] += lo; // has to be same as old l
                ans[inter[j].second.first] += inter[j].first - lo;   // take remaining
            } else {
                // l increased
                // cout << inter[j].second.first << ' ' << ro << ' ' << inter[j].first - ro << endl;
                ans[inter[j].second.first] += ro;    // has to be same as old r
                ans[inter[j].second.second] += inter[j].first - ro;  // take remaining
            }
            j++;
        }
    }

    ans[0] += l, ans[n-1] += r; // they can move boundless that way
    while (j < m) {
        ans[inter[j].second.first] += r;
        ans[inter[j].second.second] += l;
        j++;
    }

    for (int i=0; i<n; i++) cout << ans[i] << nl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...