#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 200010;
int p[N], res[N];
int dif[N];
int query[N];
int minquery[N], maxquery[N];
int32_t main(){
int n, q;
cin >> n >> q;
for(int i = 1;i <= n;i++){
cin >> p[i];
if(i > 1) dif[i-1] = p[i] - p[i-1];
}
for(int i = 1;i <= q;i++){
int x;
cin >> x;
query[i] = query[i-1] + x;
minquery[i] = min(minquery[i-1], query[i]);
maxquery[i] = max(maxquery[i-1], query[i]);
}
res[1] -= minquery[q];
//cout << '\n';
for(int i = 1;i < n;i++){
int l = 1, r = q;
int resp;
while(l <= r){
int mid = (l+r)/2;
int ans = maxquery[mid] - minquery[mid];
if(i == 5){
// cout << mid << ' ' << ans << ' ' << dif[i] << '\n';
}
if(ans >= dif[i]){
resp = mid;
r = mid-1;
}
else{
l = mid+1;
}
}
if(maxquery[q] - minquery[q] < dif[i]){
res[i] += maxquery[q];
res[i+1] -= minquery[q];
continue;
}
resp--;
res[i] += maxquery[resp];
res[i+1] -= minquery[resp];
l = p[i]+maxquery[resp];
r = p[i+1]+minquery[resp];
resp++;
if(query[resp] > 0){
res[i] += r-l;
}
else{
res[i+1] += r-l;
}
}
res[n] += maxquery[q];
for(int i = 1;i <= n;i++){
cout << res[i] << '\n';
}
}
Compilation message
Main.cpp: In function 'int32_t main()':
Main.cpp:50:13: warning: 'resp' may be used uninitialized in this function [-Wmaybe-uninitialized]
50 | resp--;
| ~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
856 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
516 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
856 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
516 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
456 KB |
Output is correct |
20 |
Correct |
57 ms |
7248 KB |
Output is correct |
21 |
Correct |
50 ms |
6996 KB |
Output is correct |
22 |
Correct |
53 ms |
6700 KB |
Output is correct |
23 |
Correct |
45 ms |
6736 KB |
Output is correct |
24 |
Correct |
51 ms |
7360 KB |
Output is correct |
25 |
Correct |
152 ms |
15076 KB |
Output is correct |
26 |
Correct |
141 ms |
14928 KB |
Output is correct |
27 |
Correct |
141 ms |
14516 KB |
Output is correct |
28 |
Correct |
153 ms |
14632 KB |
Output is correct |
29 |
Correct |
141 ms |
14320 KB |
Output is correct |
30 |
Correct |
133 ms |
13648 KB |
Output is correct |
31 |
Correct |
103 ms |
13140 KB |
Output is correct |
32 |
Correct |
97 ms |
13140 KB |
Output is correct |
33 |
Correct |
15 ms |
2140 KB |
Output is correct |
34 |
Correct |
148 ms |
15248 KB |
Output is correct |
35 |
Correct |
139 ms |
14672 KB |
Output is correct |
36 |
Correct |
147 ms |
14896 KB |
Output is correct |
37 |
Correct |
146 ms |
14988 KB |
Output is correct |
38 |
Correct |
144 ms |
14640 KB |
Output is correct |
39 |
Correct |
135 ms |
14672 KB |
Output is correct |
40 |
Correct |
114 ms |
14672 KB |
Output is correct |
41 |
Correct |
67 ms |
7768 KB |
Output is correct |
42 |
Correct |
96 ms |
13244 KB |
Output is correct |
43 |
Correct |
147 ms |
16400 KB |
Output is correct |
44 |
Correct |
65 ms |
7504 KB |
Output is correct |
45 |
Correct |
111 ms |
14764 KB |
Output is correct |
46 |
Correct |
141 ms |
16532 KB |
Output is correct |
47 |
Correct |
149 ms |
16980 KB |
Output is correct |
48 |
Correct |
151 ms |
16984 KB |
Output is correct |