# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
650206 | 2022-10-12T22:53:15 Z | milisav | Snowball (JOI21_ho_t2) | C++14 | 2 ms | 452 KB |
#include<bits/stdc++.h> #define maxn 200005 using namespace std; int n,q; long long x[maxn]; long long w[maxn]; long long a[maxn]; long long cnt[maxn]; bool sg(long long u,long long v) { if(u<=0 && v<=0) return true; if(u>=0 && v>=0) return true; return false; } int main() { scanf("%d %d",&n,&q); for(int i=0;i<n;i++) { scanf("%lld",&x[i]); } for(int i=0;i<q;i++) { scanf("%lld",&w[i]); } long long mi=0,ma=0; long long pos=w[0]; a[0]=0; a[1]=pos; mi=min(mi,pos); ma=max(ma,pos); int m=2; for(int i=1;i<q;i++) { pos+=w[i]; mi=min(mi,pos); ma=max(ma,pos); //cout<<i<<" "<<pos<<" "<<a[m-1]<<endl; if(sg(pos,a[m-1])) { if(abs(pos)>abs(a[m-1])) { a[m-1]=pos; } } else { //cout<<a[m-2]<<endl; if(abs(pos)>abs(a[m-2])) { //cout<<"inc"<<endl; a[m]=pos; m++; } } } //for(int i=0;i<m;i++) cout<<a[i]<<" "; //cout<<endl; cnt[0]-=mi; cnt[n-1]+=ma; for(int i=1;i<n;i++) { long long len=x[i]-x[i-1]; int l=1; int r=m-1; if(abs(a[r])+abs(a[r-1])<len) { if(a[r]<=0) { cnt[i]-=a[r]; cnt[i-1]+=a[r-1]; } else { cnt[i-1]+=a[r]; cnt[i]-=a[r-1]; } continue; } while(l<r) { int md=(l+r)/2; if(abs(a[md])+abs(a[md-1])<len) l=md+1; else r=md; } //cout<<i<<" "<<x[i]<<" "<<x[i-1]<<" "<<l<<" "<<a[l]<<" "<<a[l-1]<<" "<<len<<endl; if(a[l-1]<=0) { cnt[i]-=a[l-1]; cnt[i-1]+=(len+a[l-1]); } else { cnt[i-1]+=a[l-1]; cnt[i]+=(len-a[l-1]); } } for(int i=0;i<n;i++) { printf("%lld\n",cnt[i]); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | 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 | 452 KB | Output is correct |
5 | Correct | 2 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 324 KB | Output is correct |
7 | Incorrect | 2 ms | 340 KB | Output isn't correct |
8 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | 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 | 452 KB | Output is correct |
5 | Correct | 2 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 324 KB | Output is correct |
7 | Incorrect | 2 ms | 340 KB | Output isn't correct |
8 | Halted | 0 ms | 0 KB | - |