# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
378345 |
2021-03-16T14:08:12 Z |
astoria |
Snowball (JOI21_ho_t2) |
C++14 |
|
33 ms |
5228 KB |
#include "bits/stdc++.h"
using namespace std;
#define int long long
const int N=1e5+5,Q=1e5+5;
int n,q,x[N];
int pl[Q],pr[Q];
int reachL[N],reachR[N];
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin>>n>>q;
x[0]=-1e18-5e17; x[n+1]=1e18+5e17;
for(int i=1; i<=n; i++) cin>>x[i];
vector<int> seg;
for(int i=0; i<=n; i++) seg.push_back(x[i+1]-x[i]);
pl[0]=0; pr[0]=0; int po=0ll;
for(int i=1; i<=q; i++){
int v; cin>>v;
po += v;
pl[i]=min(pl[i-1],po);
pr[i]=max(pr[i-1],po);
}
pl[q+1]=-4e18; pr[q+1]=4e18;
reachL[1]=pl[q]; reachR[n]=pr[q];
for(int lo=2; lo<=q; lo++){
assert(pl[lo]==pl[lo-1] || pr[lo]==pr[lo-1]);
}
for(int i=1; i<n; i++){
int len = seg[i];
int lo=0,hi=q+1; //first pos where pl+pr >= len
while(lo<hi){
int mid=(lo+hi)>>1;
if(pr[mid]-pl[mid] >= len) hi=mid;
else lo=mid+1;
}
//cout<<lo<<endl;
if(lo==q+1){
reachR[i]=pr[q];
reachL[i+1]=pl[q];
continue;
} //case where they never meet
assert(lo!=0); //len is positive
//assert(pl[lo]==pl[lo-1] || pr[lo]==pr[lo-1] || lo==q+1); //this statement is triggered. How? Oh, Q+1 so not really
//assert(pl[lo]!=pl[lo-1] || pr[lo]!=pr[lo-1]);
if(pl[lo]!=pl[lo-1]){
reachR[i] = pr[lo-1];
reachL[i+1] = - (len - pr[lo-1]); //note reachL is negative
//cout<<"LEFTCAUSE"<<i<<endl;
} //left caused the ending
else{
reachL[i+1] = pl[lo-1];
reachR[i] = len + pl[lo-1]; //reachL is negative so it's subtraction
//cout<<"RIGHTCAUSE"<<i<<endl;
} //right caused the ending
}
for(int i=1; i<=n; i++){
cout<<reachR[i]-reachL[i]<<'\n';
}
/*for(int i=0; i<=q+1; i++){
cout<<pl[i]<<" "<<pr[i]<<endl;
}*/
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
2 ms |
492 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
492 KB |
Output is correct |
17 |
Correct |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
2 ms |
492 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
492 KB |
Output is correct |
17 |
Correct |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
492 KB |
Output is correct |
20 |
Runtime error |
33 ms |
5228 KB |
Execution killed with signal 6 |
21 |
Halted |
0 ms |
0 KB |
- |