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;
signed main(){
int n, q;
cin >> n >> q;
vector<int> x(n), l(n), r(n);
vector<int> mi(q+1), ma(q+1);
for(auto &i: x) cin >> i;
vector<int> op(q+1);
for(int i = 1; i <= q; i++){
cin >> op[i];
}
for(int i = 1; i <= q; i++){
op[i] += op[i - 1];
mi[i] = mi[i - 1];
ma[i] = ma[i - 1];
if(op[i] < op[mi[i]]) mi[i] = i;
if(op[i] > op[ma[i]]) ma[i] = i;
}
l[0] = x[0] + op[mi[q]];
r[n - 1] = x[n - 1] + op[ma[q]];
for(int i = 0; i < n - 1; i++){
int s = -1;
for(int l = 20; l >= 0; l--){
int tmp = s+(1 << l);
if(tmp >= q) continue;
if((x[i] + op[ma[tmp]] >= x[i + 1] + op[mi[tmp]])) continue;
s = tmp;
}
s++;
if(x[i] + op[ma[s]] >= x[i + 1] + op[mi[s]]){
if(ma[s] < mi[s]){
r[i] = x[i] + op[ma[s]];
l[i+1] = r[i];
}
else{
l[i + 1] = x[i + 1] + op[mi[s]];
r[i] = l[i + 1];
}
}
else{
r[i] = min(x[i + 1] + op[mi[s]], x[i] + op[ma[s]]);
l[i + 1] = max(x[i + 1] + op[mi[s]], x[i] + op[ma[s]]);
}
}
for(int i = 0; i < n; i++) cout << r[i] - l[i] << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |