#include <bits/stdc++.h>
#define int long long
using namespace std;
int x[200002];
int ans[200002];
struct Data{
int tot, l, r;
Data() = default;
Data(int _t, int _l, int _r) : tot(_t), l(_l), r(_r){};
bool operator< (const Data& o) const{
return tot < o.tot;
}
void print(){
cout << tot << ' ' << l << ' ' << r << endl;
}
};
int32_t main(){
int n, q;
cin >> n >> q;
x[0] = -(1LL << 60);
for(int i = 1; i <= n; i++){
cin >> x[i];
}
x[n + 1] = 1LL << 60;
vector<Data> v {{0, 0, 0}};
int l = 0, r = 0, x0 = 0;
for(int i = 0; i < q; i++){
int w; cin >> w;
x0 += w;
l = min(l, x0);
r = max(r, x0);
v.push_back({r - l, l, r});
}
for(int i = 0; i <= n; i++){
auto ptr = upper_bound(v.begin(), v.end(), Data{x[i + 1] - x[i], 0, 0});
Data d;
if(ptr == v.end()){
d = *prev(ptr);
}else{
Data d1 = *prev(ptr), d2 = *ptr;
int dx = d2.l != d1.l, dy = d2.r != d1.r;
d = {x[i + 1] - x[i], d1.l - dx * (x[i + 1] - x[i] - d1.tot), d1.r + dy * (x[i + 1] - x[i] - d1.tot)};
}
ans[i] += d.r, ans[i + 1] += -d.l;
}
for(int i = 1; i <= n; i++){
cout << ans[i] << ' ';
}
cout << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
3 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
480 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
316 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
3 ms |
460 KB |
Output is correct |
16 |
Correct |
3 ms |
468 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
468 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 |
328 KB |
Output is correct |
4 |
Correct |
3 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
480 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
316 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
3 ms |
460 KB |
Output is correct |
16 |
Correct |
3 ms |
468 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
103 ms |
8160 KB |
Output is correct |
21 |
Correct |
77 ms |
8060 KB |
Output is correct |
22 |
Correct |
74 ms |
7996 KB |
Output is correct |
23 |
Correct |
78 ms |
7788 KB |
Output is correct |
24 |
Correct |
76 ms |
8080 KB |
Output is correct |
25 |
Correct |
197 ms |
13504 KB |
Output is correct |
26 |
Correct |
190 ms |
13456 KB |
Output is correct |
27 |
Correct |
189 ms |
13100 KB |
Output is correct |
28 |
Correct |
192 ms |
13304 KB |
Output is correct |
29 |
Correct |
182 ms |
12744 KB |
Output is correct |
30 |
Correct |
185 ms |
12172 KB |
Output is correct |
31 |
Correct |
146 ms |
11632 KB |
Output is correct |
32 |
Correct |
143 ms |
11892 KB |
Output is correct |
33 |
Correct |
21 ms |
1756 KB |
Output is correct |
34 |
Correct |
204 ms |
14024 KB |
Output is correct |
35 |
Correct |
187 ms |
13244 KB |
Output is correct |
36 |
Correct |
236 ms |
13536 KB |
Output is correct |
37 |
Correct |
191 ms |
13324 KB |
Output is correct |
38 |
Correct |
186 ms |
13136 KB |
Output is correct |
39 |
Correct |
193 ms |
13360 KB |
Output is correct |
40 |
Correct |
168 ms |
13464 KB |
Output is correct |
41 |
Correct |
102 ms |
8572 KB |
Output is correct |
42 |
Correct |
139 ms |
11692 KB |
Output is correct |
43 |
Correct |
212 ms |
15084 KB |
Output is correct |
44 |
Correct |
97 ms |
8444 KB |
Output is correct |
45 |
Correct |
188 ms |
13204 KB |
Output is correct |
46 |
Correct |
206 ms |
15224 KB |
Output is correct |
47 |
Correct |
221 ms |
15436 KB |
Output is correct |
48 |
Correct |
213 ms |
15516 KB |
Output is correct |