#include<bits/stdc++.h>
using namespace std;
int main(){
long long n, q;
cin >> n >> q;
vector<long long> a;
for(long long i = 0; i < n; i++){
long long t;
cin >> t;
a.push_back(t);
}
vector<long long> l={0};
vector<long long> r={0};
long long ll=-10, lr=-10, loc = 0, l1=0, r1=0;
long long f = -1;
for(long long i = 0; i < q; i++){
long long t = 0;
cin >> t;
loc+=t;
if(loc<l1){
if(f==-1) f=0;
l1=loc;
if(ll>lr){
l[l.size()-1]=loc;
}else{
l.push_back(loc);
}
ll=i;
}
if(loc>r1){
if(f==-1) f=1;
r1=loc;
if(ll<lr){
r[r.size()-1]=loc;
}else{
r.push_back(loc);
}
lr=i;
}
}
/* for(long long i = 0; i < l.size(); i++){
cout << l[i] << ' ';
}
cout << "\n\n";
for(long long i = 0; i < r.size(); i++){
cout << r[i] << ' ';
}
cout << "\n\n";*/
long long ls[n], rs[n];
ls[0]=a[0]+l1;
rs[n-1]=a[n-1]+r1;
for(long long i = 0; i < n-1; i++){
if(a[i+1]-a[i]>r1-l1){
rs[i]=a[i]+r1;
ls[i+1]=a[i+1]+l1;
continue;
}
long long lb=0, rb=l.size()+r.size()-1, mid;
//l[(mid+1-f)/2]
//r[(mid+f)/2]
while(lb!=rb-1){
mid=(lb+rb)/2;
if(r[(mid+f)/2]-l[(mid+1-f)/2]<a[i+1]-a[i])lb=mid;
else rb=mid;
}
// cout << lb << ' ' << rb << '\n';
// cout << a[i]+r[(lb+f)/2] << ' ' << a[i+1]+l[(lb+1-f)/2] << "\n\n";
if((lb+f+1)%2){
rs[i]=a[i]+r[(lb+f)/2];
ls[i+1]=a[i]+r[(lb+f)/2];
}else{
rs[i]=a[i+1]+l[(lb+1-f)/2];
ls[i+1]=a[i+1]+l[(lb+1-f)/2];
}
}
// cout << '\n';
for(long long i = 0; i < n; i++){
cout <<rs[i]-ls[i] << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
312 KB |
Output is correct |
6 |
Correct |
3 ms |
340 KB |
Output is correct |
7 |
Correct |
4 ms |
308 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
308 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
3 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
356 KB |
Output is correct |
17 |
Correct |
2 ms |
308 KB |
Output is correct |
18 |
Correct |
1 ms |
300 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
312 KB |
Output is correct |
6 |
Correct |
3 ms |
340 KB |
Output is correct |
7 |
Correct |
4 ms |
308 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
308 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
3 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
356 KB |
Output is correct |
17 |
Correct |
2 ms |
308 KB |
Output is correct |
18 |
Correct |
1 ms |
300 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
92 ms |
3104 KB |
Output is correct |
21 |
Correct |
82 ms |
3308 KB |
Output is correct |
22 |
Correct |
72 ms |
3036 KB |
Output is correct |
23 |
Correct |
74 ms |
2732 KB |
Output is correct |
24 |
Correct |
72 ms |
3572 KB |
Output is correct |
25 |
Correct |
216 ms |
9756 KB |
Output is correct |
26 |
Correct |
199 ms |
9684 KB |
Output is correct |
27 |
Correct |
191 ms |
9404 KB |
Output is correct |
28 |
Correct |
211 ms |
9432 KB |
Output is correct |
29 |
Correct |
185 ms |
8792 KB |
Output is correct |
30 |
Correct |
200 ms |
7856 KB |
Output is correct |
31 |
Correct |
143 ms |
7368 KB |
Output is correct |
32 |
Correct |
141 ms |
7492 KB |
Output is correct |
33 |
Correct |
23 ms |
1480 KB |
Output is correct |
34 |
Correct |
197 ms |
8520 KB |
Output is correct |
35 |
Correct |
194 ms |
8460 KB |
Output is correct |
36 |
Correct |
208 ms |
9708 KB |
Output is correct |
37 |
Correct |
191 ms |
9364 KB |
Output is correct |
38 |
Correct |
193 ms |
9496 KB |
Output is correct |
39 |
Correct |
199 ms |
9476 KB |
Output is correct |
40 |
Correct |
188 ms |
9596 KB |
Output is correct |
41 |
Correct |
99 ms |
2184 KB |
Output is correct |
42 |
Correct |
141 ms |
7332 KB |
Output is correct |
43 |
Correct |
238 ms |
11548 KB |
Output is correct |
44 |
Correct |
104 ms |
3888 KB |
Output is correct |
45 |
Correct |
171 ms |
9428 KB |
Output is correct |
46 |
Correct |
221 ms |
11644 KB |
Output is correct |
47 |
Correct |
247 ms |
8696 KB |
Output is correct |
48 |
Correct |
234 ms |
8648 KB |
Output is correct |