This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
signed main() {
ll n, q;
cin>>n>>q;
vector<ll>pos(n);
for(ll i=0;i<n;i++){
cin>>pos[i];
}
vector<pair<ll,ll>>rangos;
rangos.push_back({0,0});
ll ml=0,rr=0;
ll suma=0;
for(ll i=0;i<q;i++){
ll w;
cin>>w;
suma+=w;
rr=max(suma,rr);
ml=min(suma,ml);
rangos.push_back({ml,rr});
}
vector<ll>amplitud(n,0LL);
amplitud[0]=-rangos[rangos.size()-1].first;
amplitud[n-1]+=rangos[rangos.size()-1].second;
for(ll i=0LL;i<n-1;i++){
ll l=0,r=rangos.size();
while(l<r){
ll mid=(l+r)/2;
if(pos[i]+rangos[mid].second>pos[i+1]+rangos[mid].first){
r=mid;
}
else{
l=mid+1;
}
}
cerr << "bs = " << l << endl;
ll dir=0;
if(l==rangos.size()){
amplitud[i]+=rangos[l-1].second;
amplitud[i+1]+=-rangos[l-1].first;
continue;
}
if(rangos[l].first<rangos[l-1].first)dir=-1;
else dir=1;
ll e=0;
if(dir==1){
amplitud[i+1]+=abs(min(0LL,rangos[l].first));
ll diff=pos[i+1]-abs(min(0LL,rangos[l].first));
diff=max(0LL,diff-pos[i]);
amplitud[i]+=diff;
}
else{
amplitud[i]+=abs(max(0LL,rangos[l].second));
ll diff=pos[i]+abs(max(0LL,rangos[l].second));
diff=max(0LL,pos[i+1]-diff);
amplitud[i+1]+=diff;
}
}
for(ll i=0;i<n;i++){
cout<<amplitud[i]<<"\n";
}
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:39:7: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | if(l==rangos.size()){
| ~^~~~~~~~~~~~~~~
Main.cpp:46:6: warning: unused variable 'e' [-Wunused-variable]
46 | ll e=0;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |