Submission #560463

#TimeUsernameProblemLanguageResultExecution timeMemory
560463messiuuuuuSnowball (JOI21_ho_t2)C++14
100 / 100
144 ms13780 KiB
#include<bits/stdc++.h> #define task "C" #define ll long long #define ld long double #define fi first #define se second #define pb push_back #define int long long using namespace std; const int MAXN = 2e5 + 5; const ll INF = 1e18 + 5; int n, q; ll x[MAXN]; void Input() { cin >> n >> q; for (int i = 1; i <= n; i++) { cin >> x[i]; } } int cs[MAXN], l[MAXN], r[MAXN]; void Solve() { x[0] = -INF; iota(cs + 1, cs + 1 + n, 1); sort(cs + 1, cs + 1 + n, [](int i, int j) { return x[i] - x[i - 1] < x[j] - x[j - 1]; }); int i = 1; ll cur = 0, maxl = 0, maxr = 0; while (q-- > 0) { ll w; cin >> w; cur += w; maxr = max(maxr, cur); maxl = min(maxl, cur); for (; i <= n && x[cs[i]] - x[cs[i] - 1] <= maxr - maxl; i++) { if (w < 0) { r[cs[i] - 1] = x[cs[i] - 1] + maxr; l[cs[i]] = x[cs[i] - 1] + maxr; } else { r[cs[i] - 1] = x[cs[i]] + maxl; l[cs[i]] = x[cs[i]] + maxl; } } } for (; i <= n; i++) { r[cs[i] - 1] = x[cs[i] - 1] + maxr; l[cs[i]] = x[cs[i]] + maxl; } //r[cs[n]] = x[cs[n]] + maxr; r[n] = x[n] + maxr; l[1] = x[1] + maxl; //cout << r[2] << '\n'; for (int i = 1; i <= n; i++) { cout << r[i] - l[i] << '\n'; } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); //freopen(task".INP","r",stdin); //freopen(task".OUT","w",stdout); Input(); Solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...