# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
762704 | sheldon | Snowball (JOI21_ho_t2) | C++14 | 1 ms | 340 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
int n, q;
cin >> n >> q;
vector<long long> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<array<long long, 3>> v;
vector<int> ans(n);
for (int i = 0; i + 1 < n; ++i) {
v.push_back({abs(a[i] - a[i + 1]), 1LL * i, 1LL * i + 1});
}
sort(v.begin(), v.end());
long long l = 0, r = 0, delta = 0;
long long A, B;
vector<long long> deltas;
for (int i = 0; i < q; ++i) {
long long x;
cin >> x;
delta += x;
if (delta < l || delta > r) {
deltas.push_back(delta);
}
l = min(delta, l);
r = max(delta, r);
}
A = l, B = r;
l = 0, r = 0;
long long prev_l = 0, prev_r = 0;
int idx = 0;
for (int i = 0; i < v.size(); ++i) {
while (idx < deltas.size() && a[v[i][1]] + r < a[v[i][2]] + l) {
l = min(l, deltas[idx]);
r = max(r, deltas[idx]);
++idx;
}
if (a[v[i][1]] + r > a[v[i][2]] + l) {
if (deltas[idx - 1] < 0) {
ans[v[i][1]] += r;
ans[v[i][2]] += v[i][0] - r;
} else {
ans[v[i][2]] += abs(l);
ans[v[i][1]] += v[i][0] - abs(l);
}
} else {
ans[v[i][2]] += abs(l);
ans[v[i][1]] += r;
}
}
ans[0] += abs(l);
ans[n - 1] += r;
for (long long x : ans) {
cout << x << '\n';
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |