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>
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
#define jizz ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
using namespace std;
ll n, q;
ll x[200005];
ll h[200005];
ll rag[200005][2];
ll ans[200005];
struct line{
ll i, v;
};
vector <line> val;
bool operator <(line a, line b){
return a.v<b.v;
}
int main() {
scanf("%lld%lld", &n, &q);
for(ll i = 0; i < n; i++) scanf("%lld", x+i);
for(ll i = 0; i < q; i++) scanf("%lld", h+i);
ll now = 0;
for(ll i = 1; i <= q; i++){
now+=h[i-1];
rag[i][0] = min(rag[i-1][0], now);
rag[i][1] = max(rag[i-1][1], now);
}
for(ll i = 0; i < n-1; i++){
val.push_back({i,x[i+1]-x[i]});
}
sort(val.begin(), val.end());
ll ind = 0;
if(n>1){
for(ll i = 1; i <= q; i++){
while(ind<val.size()&&val[ind].v<=rag[i][1]-rag[i][0]){
ans[val[ind].i]+=rag[i-1][1];
ans[val[ind].i+1]-=rag[i-1][0];
if(h[i-1]>0){
ans[val[ind].i]+=val[ind].v-rag[i-1][1]+rag[i-1][0];
}else{
ans[val[ind].i+1]+=val[ind].v-rag[i-1][1]+rag[i-1][0];
}
ind++;
if(ind>=n-1) break;
}
}
for(ll i = ind; i < n-1; i++){
ans[val[i].i]+=rag[q][1];
ans[val[i].i+1]-=rag[q][0];
}
}
ans[n-1]+=rag[q][1];
ans[0]-=rag[q][0];
for(ll i = 0; i < n; i++) printf("%lld\n", ans[i]);
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:38:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<line>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | while(ind<val.size()&&val[ind].v<=rag[i][1]-rag[i][0]){
| ~~~^~~~~~~~~~~
Main.cpp:22:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | scanf("%lld%lld", &n, &q);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:23:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | for(ll i = 0; i < n; i++) scanf("%lld", x+i);
| ~~~~~^~~~~~~~~~~~~
Main.cpp:24:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | for(ll i = 0; i < q; i++) scanf("%lld", h+i);
| ~~~~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |