Submission #1174367

#TimeUsernameProblemLanguageResultExecution timeMemory
1174367Hamed_GhaffariSnowball (JOI21_ho_t2)C++20
0 / 100
0 ms320 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const int MXN = 2e5+5; int n, q; ll x[MXN], w[MXN], ans[MXN]; int32_t main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); cin >> n >> q; for(int i=1; i<=n; i++) cin >> x[i]; ll mn = 0, mx = 0; for(int i=1; i<=q; i++ ){ cin >> w[i]; w[i] += w[i-1]; mn = min(mn, w[i]); mx = max(mx, w[i]); } vector<pair<ll, ll>> v1={{0,0}}, v2={{0,0}}; for(int i=1; i<=q; i++) { if(w[i]>v1.back().first) v1.push_back({w[i], i}); if(-w[i]>v2.back().first) v2.push_back({-w[i], i}); } for(int i=1; i<n; i++) if(x[i]+mx < x[i+1]+mn) { ans[i] += mx; ans[i+1] += -mn; } else { ll l=x[i], r=x[i+1]+1, m; while(r-l>1) { m = ((l+r)/2); bool bad=0; int pos1 = v1[lower_bound(v1.begin(), v1.end(), make_pair(m-x[i], 0ll))-v1.begin()].second; int pos2 = v2[lower_bound(v2.begin(), v2.end(), make_pair(-(m-1-x[i+1]),0ll))-v2.begin()].second; (pos2<pos1 ? r : l) = m; } ans[i] += l-x[i]; ans[i+1] += x[i+1]-l; } ans[1] -= mn; ans[n] += mx; for(int i=1; i<=n; i++) cout << ans[i] << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...