#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N, Q;
cin >> N >> Q;
vector<long long> X(N);
for (int i = 0; i < N; i++) {
cin >> X[i];
}
vector<long long> W(Q);
for (int i = 0; i < Q; i++) {
cin >> W[i];
}
long long current_x = 0;
vector<long long> L(Q + 1), R(Q + 1);
for (int i = 1; i <= Q; i++) {
current_x += W[i - 1];
L[i] = min(L[i - 1], current_x);
R[i] = max(R[i - 1], current_x);
}
vector<long long> ans(N);
for (int i = 0; i < N; i++) {
long long ansL, ansR;
if (i == 0) {
ansL = X[i] + L[Q];
} else {
int lo = 0, hi = Q;
while (lo < hi) {
int md = (lo + hi + 1) / 2;
if (X[i - 1] + R[md] <= X[i] + L[md]) {
lo = md;
} else {
hi = md - 1;
}
}
assert(X[i - 1] + R[lo] <= X[i] + L[lo]);
if (lo < Q && W[lo] < 0) {
ansL = X[i - 1] + R[lo];
} else {
ansL = X[i] + L[lo];
}
}
if (i + 1 == N) {
ansR = X[i] + R[Q];
} else {
int lo = 0, hi = Q;
while (lo < hi) {
int md = (lo + hi + 1) / 2;
if (X[i] + R[md] <= X[i + 1] + L[md]) {
lo = md;
} else {
hi = md - 1;
}
}
assert(X[i] + R[lo] <= X[i + 1] + L[lo]);
if (lo < Q && W[lo] > 0) {
ansR = X[i + 1] + L[lo];
} else {
ansR = X[i] + R[lo];
}
}
ans[i] = ansR - ansL;
}
for (int i = 0; i < N; i++) {
cout << ans[i] << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
2 ms |
492 KB |
Output is correct |
7 |
Correct |
2 ms |
492 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
2 ms |
492 KB |
Output is correct |
17 |
Correct |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
0 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
2 ms |
492 KB |
Output is correct |
7 |
Correct |
2 ms |
492 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
2 ms |
492 KB |
Output is correct |
17 |
Correct |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
0 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
32 ms |
4972 KB |
Output is correct |
21 |
Correct |
31 ms |
4972 KB |
Output is correct |
22 |
Correct |
30 ms |
4972 KB |
Output is correct |
23 |
Correct |
33 ms |
5100 KB |
Output is correct |
24 |
Correct |
38 ms |
5484 KB |
Output is correct |
25 |
Correct |
156 ms |
9764 KB |
Output is correct |
26 |
Correct |
145 ms |
9708 KB |
Output is correct |
27 |
Correct |
144 ms |
9580 KB |
Output is correct |
28 |
Correct |
147 ms |
9580 KB |
Output is correct |
29 |
Correct |
143 ms |
9324 KB |
Output is correct |
30 |
Correct |
131 ms |
8940 KB |
Output is correct |
31 |
Correct |
92 ms |
8684 KB |
Output is correct |
32 |
Correct |
74 ms |
8684 KB |
Output is correct |
33 |
Correct |
13 ms |
1388 KB |
Output is correct |
34 |
Correct |
149 ms |
9764 KB |
Output is correct |
35 |
Correct |
145 ms |
9580 KB |
Output is correct |
36 |
Correct |
146 ms |
9856 KB |
Output is correct |
37 |
Correct |
143 ms |
9580 KB |
Output is correct |
38 |
Correct |
142 ms |
9580 KB |
Output is correct |
39 |
Correct |
139 ms |
9600 KB |
Output is correct |
40 |
Correct |
100 ms |
9580 KB |
Output is correct |
41 |
Correct |
33 ms |
4972 KB |
Output is correct |
42 |
Correct |
73 ms |
8684 KB |
Output is correct |
43 |
Correct |
115 ms |
9836 KB |
Output is correct |
44 |
Correct |
37 ms |
4972 KB |
Output is correct |
45 |
Correct |
81 ms |
9580 KB |
Output is correct |
46 |
Correct |
107 ms |
9836 KB |
Output is correct |
47 |
Correct |
106 ms |
9836 KB |
Output is correct |
48 |
Correct |
107 ms |
9836 KB |
Output is correct |