/**
____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N_MAX = 200000;
const int Q_MAX = 200000;
int N, Q;
ll X[N_MAX + 2];
ll W[Q_MAX + 2];
ll tr[Q_MAX + 2];
ll mxl[Q_MAX + 2];
ll mxr[Q_MAX + 2];
ll answer[N_MAX + 2];
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> N >> Q;
for (int i = 1; i <= N; i++) {
cin >> X[i];
}
for (int q = 1; q <= Q; q++) {
cin >> W[q];
}
for (int q = 1; q <= Q; q++) {
tr[q] = tr[q - 1] + W[q];
mxl[q] = max(mxl[q - 1], -tr[q]);
mxr[q] = max(mxr[q - 1], +tr[q]);
}
for (int i = 1; i + 1 <= N; i++) {
int l = 0, r = Q;
while (l < r) {
int mid = (l + r + 1) / 2;
if (mxl[mid] + mxr[mid] < X[i + 1] - X[i]) {
l = mid;
} else {
r = mid - 1;
}
}
int join = l + 1;
answer[i] += mxr[join - 1];
answer[i + 1] += mxl[join - 1];
if (join <= Q) {
answer[(W[join] > 0 ? i : i + 1)] += (X[i + 1] - X[i]) - (mxl[join - 1] + mxr[join - 1]);
}
}
answer[1] += mxl[Q];
answer[N] += mxr[Q];
for (int i = 1; i <= N; i++) {
cout << answer[i] << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
508 KB |
Output is correct |
6 |
Correct |
2 ms |
476 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
472 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
508 KB |
Output is correct |
6 |
Correct |
2 ms |
476 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
472 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
28 ms |
8720 KB |
Output is correct |
21 |
Correct |
27 ms |
8524 KB |
Output is correct |
22 |
Correct |
26 ms |
8308 KB |
Output is correct |
23 |
Correct |
24 ms |
8108 KB |
Output is correct |
24 |
Correct |
33 ms |
8632 KB |
Output is correct |
25 |
Correct |
128 ms |
14996 KB |
Output is correct |
26 |
Correct |
97 ms |
14912 KB |
Output is correct |
27 |
Correct |
103 ms |
14552 KB |
Output is correct |
28 |
Correct |
116 ms |
14780 KB |
Output is correct |
29 |
Correct |
96 ms |
14264 KB |
Output is correct |
30 |
Correct |
93 ms |
13644 KB |
Output is correct |
31 |
Correct |
70 ms |
13104 KB |
Output is correct |
32 |
Correct |
59 ms |
13192 KB |
Output is correct |
33 |
Correct |
10 ms |
1876 KB |
Output is correct |
34 |
Correct |
101 ms |
15284 KB |
Output is correct |
35 |
Correct |
112 ms |
14784 KB |
Output is correct |
36 |
Correct |
105 ms |
14948 KB |
Output is correct |
37 |
Correct |
108 ms |
14776 KB |
Output is correct |
38 |
Correct |
99 ms |
14608 KB |
Output is correct |
39 |
Correct |
101 ms |
14916 KB |
Output is correct |
40 |
Correct |
75 ms |
14744 KB |
Output is correct |
41 |
Correct |
29 ms |
9268 KB |
Output is correct |
42 |
Correct |
56 ms |
13208 KB |
Output is correct |
43 |
Correct |
81 ms |
16612 KB |
Output is correct |
44 |
Correct |
31 ms |
9088 KB |
Output is correct |
45 |
Correct |
75 ms |
14668 KB |
Output is correct |
46 |
Correct |
83 ms |
16672 KB |
Output is correct |
47 |
Correct |
81 ms |
16844 KB |
Output is correct |
48 |
Correct |
95 ms |
16888 KB |
Output is correct |