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;
using ll = long long;
const int N = 1e6 + 66;
const ll INF = 1e18 + 123;
ll L[N], R[N], x[N], shit[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n, q;
cin >> n >> q;
for (int i = 1 ; i <= n ; ++ i) cin >> x[i];
x[n + 1] = INF, x[0] = -INF;
ll loc = 0;
for (int i = 1 ; i <= q ; ++ i) {
ll W; cin >> W;
loc += W;
L[i] = min(L[i - 1], loc);
R[i] = max(R[i - 1], loc);
}
for (int i = 1 ; i <= n ; ++ i) {
ll l = max(x[i - 1], x[i] + L[q]), r = x[i];
while (l < r) {
ll m = (l + r) >> 1ll;
int tl = 0, tr = q;
while (tl < tr) {
int tm = (tl + tr) >> 1;
if (x[i] + L[tm] <= m) {
tr = tm;
} else {
tl = tm + 1;
}
}
if (x[i - 1] + R[tr] <= m) {
r = m;
} else {
l = m + 1;
}
}
//cerr << i << " " << x[i] << " L reach: " << r << "\n";
shit[i] += x[i] - r;
}
for (int i = 1 ; i <= n ; ++ i) {
ll l = x[i], r = min(x[i + 1], x[i] + R[q]);
while (l < r) {
ll m = (l + r + 1) >> 1ll;
int tl = 0, tr = q;
while (tl < tr) {
int tm = (tl + tr) >> 1;
if (R[tm] + x[i] >= m) {
tr = tm;
} else {
tl = tm + 1;
}
}
if (x[i + 1] + L[tr] >= m) {
l = m;
} else {
r = m - 1;
}
}
//cerr << i << " " << x[i] << " R reach: " << l << "\n";
shit[i] += l - x[i];
}
for (int i = 1 ; i <= n ; ++ i) {
cout << shit[i] << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |