제출 #1329994

#제출 시각아이디문제언어결과실행 시간메모리
1329994nguyenkhangninh99Snowball (JOI21_ho_t2)C++20
100 / 100
105 ms13216 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n, q; cin >> n >> q;
    vector<int> okl(n + 1), okr(n + 1), res(n + 1), x(n + 1);
    for(int i = 1; i <= n; i++) cin >> x[i];

    priority_queue<array<int, 3>> pq;
    for(int i = 2; i <= n; i++) pq.push({-(x[i] - x[i - 1]), i - 1, i});

    int pre = 0, mn = 0, mx = 0;
    for(int i = 0; i < q; ++i){
        int w; cin >> w;
        pre += w;
        mn = min(mn, pre);
        mx = max(mx, pre);
        while(!pq.empty() && mx - mn >= -pq.top()[0]){
            auto [dist, a, b] = pq.top();
            pq.pop();
            if(w > 0) res[a] += -dist + mn, res[b] -= mn;
            else res[a] += mx, res[b] += -dist - mx;
            okr[a] = okl[b] = true;
        }
    }
    for(int i = 1; i <= n; i++) cout << res[i] + (!okr[i]) * mx + (!okl[i]) * -mn << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...