/**
____ ____ ____ ____ ____
||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];
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
380 KB |
Output is correct |
4 |
Incorrect |
2 ms |
596 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
380 KB |
Output is correct |
4 |
Incorrect |
2 ms |
596 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |