#include<bits/stdc++.h>
using namespace std;
mt19937 rnd(51);
#define ll long long
#define pb push_back
#define ld long double
const ll INF = 1e18;
signed main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif // LOCAL
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<ll> x(n), w(q), ans(n);
for (int i = 0; i < n; i++) {
cin >> x[i];
}
ll cur = 0, mn = 0, mx = 0;
vector<ll> u{-INF, INF};
for (int i = 0; i < q; i++) {
cin >> w[i];
cur += w[i];
mn = min(mn, cur);
mx = max(mx, cur);
u.pb(cur);
}
sort(u.begin(), u.end());
u.erase(unique(u.begin(), u.end()), u.end());
int m = u.size();
vector<int> pr(m, q), sf(m, q);
cur = 0;
for (int i = 0; i < q; i++) {
cur += w[i];
int j = lower_bound(u.begin(), u.end(), cur) - u.begin();
pr[j] = min(pr[j], i);
sf[j] = min(sf[j], i);
}
for (int i = 1; i < m; i++) {
pr[i] = min(pr[i], pr[i - 1]);
}
for (int i = m - 2; i >= 0; i--) {
sf[i] = min(sf[i], sf[i + 1]);
}
for (int i = 0; i + 1 < n; i++) {
ll l = 0, r = x[i + 1] - x[i] + 1, d = x[i + 1] - x[i];
if (abs(mn) + mx <= x[i + 1] - x[i]) {
ans[i] += mx;
ans[i + 1] += abs(mn);
continue;
}
while (r - l > 1) {
ll mid = (r + l) / 2;
int j = lower_bound(u.begin(), u.end(), mid) - u.begin();
int k = upper_bound(u.begin(), u.end(), -(d - mid + 1)) - u.begin() - 1;
if (sf[j] < pr[k]) {
l = mid;
} else {
r = mid;
}
}
ans[i] += l;
ans[i + 1] += d - l;
}
ans[0] += abs(mn);
ans.back() += abs(mx);
for (int i = 0; i < n; i++) {
cout << ans[i] << endl;
}
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 |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
7 ms |
408 KB |
Output is correct |
5 |
Correct |
7 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
340 KB |
Output is correct |
7 |
Correct |
5 ms |
448 KB |
Output is correct |
8 |
Correct |
6 ms |
340 KB |
Output is correct |
9 |
Correct |
6 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
332 KB |
Output is correct |
11 |
Correct |
3 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
7 ms |
468 KB |
Output is correct |
16 |
Correct |
7 ms |
468 KB |
Output is correct |
17 |
Correct |
5 ms |
536 KB |
Output is correct |
18 |
Correct |
0 ms |
324 KB |
Output is correct |
19 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
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 |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
7 ms |
408 KB |
Output is correct |
5 |
Correct |
7 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
340 KB |
Output is correct |
7 |
Correct |
5 ms |
448 KB |
Output is correct |
8 |
Correct |
6 ms |
340 KB |
Output is correct |
9 |
Correct |
6 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
332 KB |
Output is correct |
11 |
Correct |
3 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
7 ms |
468 KB |
Output is correct |
16 |
Correct |
7 ms |
468 KB |
Output is correct |
17 |
Correct |
5 ms |
536 KB |
Output is correct |
18 |
Correct |
0 ms |
324 KB |
Output is correct |
19 |
Correct |
3 ms |
340 KB |
Output is correct |
20 |
Correct |
49 ms |
7100 KB |
Output is correct |
21 |
Correct |
47 ms |
6956 KB |
Output is correct |
22 |
Correct |
64 ms |
6756 KB |
Output is correct |
23 |
Correct |
58 ms |
6636 KB |
Output is correct |
24 |
Correct |
147 ms |
7080 KB |
Output is correct |
25 |
Correct |
1058 ms |
13576 KB |
Output is correct |
26 |
Correct |
1026 ms |
13448 KB |
Output is correct |
27 |
Correct |
996 ms |
12976 KB |
Output is correct |
28 |
Correct |
976 ms |
12848 KB |
Output is correct |
29 |
Correct |
857 ms |
11840 KB |
Output is correct |
30 |
Correct |
432 ms |
10700 KB |
Output is correct |
31 |
Correct |
314 ms |
10312 KB |
Output is correct |
32 |
Correct |
268 ms |
10256 KB |
Output is correct |
33 |
Correct |
92 ms |
1656 KB |
Output is correct |
34 |
Correct |
1053 ms |
13712 KB |
Output is correct |
35 |
Correct |
1006 ms |
13092 KB |
Output is correct |
36 |
Correct |
1069 ms |
13388 KB |
Output is correct |
37 |
Correct |
977 ms |
13072 KB |
Output is correct |
38 |
Correct |
1041 ms |
12808 KB |
Output is correct |
39 |
Correct |
1008 ms |
13024 KB |
Output is correct |
40 |
Correct |
555 ms |
13088 KB |
Output is correct |
41 |
Correct |
43 ms |
7748 KB |
Output is correct |
42 |
Correct |
272 ms |
10252 KB |
Output is correct |
43 |
Correct |
479 ms |
14916 KB |
Output is correct |
44 |
Correct |
56 ms |
7616 KB |
Output is correct |
45 |
Correct |
330 ms |
13060 KB |
Output is correct |
46 |
Correct |
534 ms |
15096 KB |
Output is correct |
47 |
Correct |
494 ms |
14276 KB |
Output is correct |
48 |
Correct |
484 ms |
15300 KB |
Output is correct |