#include <bits/stdc++.h>
#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 2e5+5;
int arr[N], mn[N], mx[N], ans[N], ask[N];
int now = 0;
signed main(){
fastio
int n,q;
cin >> n >> q;
for(int i = 1;i <= n;i++){
cin >> arr[i];
}
for(int i = 1;i <= q;i++){
cin >> ask[i];
now += ask[i];
mn[i] = min(mn[i-1],now);
mx[i] = max(mx[i-1],now);
}
ans[1] -= mn[q], ans[n] += mx[q];
for(int i = 1;i <= n-1;i++){
int dis = arr[i+1]-arr[i];
int l = 0, r = q;
while(l < r){
int mid = (l+r+1)>>1;
if(mx[mid]-mn[mid] <= dis) l = mid;
else r = mid-1;
}
ans[i] += mx[l], ans[i+1] -= mn[l];
if(l != q){
if(ask[l+1]>0){
ans[i] += dis-(mx[l]-mn[l]);
}else{
ans[i+1] += dis-(mx[l]-mn[l]);
}
}
}
for(int i = 1;i <= n;i++){
cout << ans[i] << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
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 |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
27 ms |
4968 KB |
Output is correct |
21 |
Correct |
24 ms |
4948 KB |
Output is correct |
22 |
Correct |
23 ms |
4936 KB |
Output is correct |
23 |
Correct |
24 ms |
5076 KB |
Output is correct |
24 |
Correct |
30 ms |
6900 KB |
Output is correct |
25 |
Correct |
101 ms |
13388 KB |
Output is correct |
26 |
Correct |
110 ms |
13268 KB |
Output is correct |
27 |
Correct |
94 ms |
13048 KB |
Output is correct |
28 |
Correct |
128 ms |
13172 KB |
Output is correct |
29 |
Correct |
98 ms |
12752 KB |
Output is correct |
30 |
Correct |
87 ms |
11980 KB |
Output is correct |
31 |
Correct |
65 ms |
11448 KB |
Output is correct |
32 |
Correct |
66 ms |
11632 KB |
Output is correct |
33 |
Correct |
10 ms |
1700 KB |
Output is correct |
34 |
Correct |
96 ms |
13744 KB |
Output is correct |
35 |
Correct |
107 ms |
13128 KB |
Output is correct |
36 |
Correct |
98 ms |
13388 KB |
Output is correct |
37 |
Correct |
104 ms |
13104 KB |
Output is correct |
38 |
Correct |
103 ms |
12996 KB |
Output is correct |
39 |
Correct |
94 ms |
13180 KB |
Output is correct |
40 |
Correct |
86 ms |
13172 KB |
Output is correct |
41 |
Correct |
38 ms |
7660 KB |
Output is correct |
42 |
Correct |
59 ms |
11648 KB |
Output is correct |
43 |
Correct |
80 ms |
14964 KB |
Output is correct |
44 |
Correct |
29 ms |
7612 KB |
Output is correct |
45 |
Correct |
66 ms |
13120 KB |
Output is correct |
46 |
Correct |
78 ms |
14976 KB |
Output is correct |
47 |
Correct |
82 ms |
15272 KB |
Output is correct |
48 |
Correct |
79 ms |
15312 KB |
Output is correct |