#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#ifndef LOCAL
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt")
#endif
using namespace std;
using ll = long long;
using ld = long double;
#define x first
#define y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
mt19937 mt(123);
void solve();
void init();
int32_t main() {
#ifndef LOCAL
cin.tie(nullptr)->sync_with_stdio(false);
#endif
cout << fixed << setprecision(30);
init();
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
void init() {}
const int N = 200200;
ll x[N], w[N], mn[N], mx[N], ans[N];
void solve() {
int n, q;
cin >> n >> q;
for (int i = 0; i < n; i++) {
cin >> x[i];
}
for (int i = 0; i < q; i++) {
ll nw;
cin >> nw;
w[i + 1] = w[i] + nw;
}
for (int i = 1; i <= q; i++) {
mn[i] = min(mn[i - 1], w[i]);
mx[i] = max(mx[i - 1], w[i]);
}
for (int i = 0; i < n; i++) {
if (i) {
ll dist = x[i] - x[i - 1];
if (dist >= mx[q] - mn[q]) {
ans[i] -= mn[q];
}
int l = 0, r = q;
while (r - l > 1) {
int m = (r + l) / 2;
if (mx[m] - mn[m] >= dist) {
r = m;
} else {
l = m;
}
}
if (mx[r] != mx[l]) {
ans[i] -= mn[r];
} else {
ans[i] += dist - mx[r];
}
} else {
ans[i] -= mn[q];
}
if (i + 1 < n) {
ll dist = x[i + 1] - x[i];
if (dist >= mx[q] - mn[q]) {
ans[i] += mx[q];
}
int l = 0, r = q;
while (r - l > 1) {
int m = (r + l) / 2;
if (mx[m] - mn[m] >= dist) {
r = m;
} else {
l = m;
}
}
if (r == q + 1 || mn[r] != mn[l]) {
ans[i] += mx[r];
} else {
ans[i] += dist + mn[r];
}
} else {
ans[i] += mx[q];
}
}
for (int i = 0; i < n; i++) {
cout << ans[i] << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |