# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
620816 | patrikpavic2 | Snowball (JOI21_ho_t2) | C++17 | 138 ms | 15308 KiB |
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 <cstdio>
#include <algorithm>
using namespace std;
const int N = 2e5 + 500;
typedef long long ll;
int n, q;
ll A[N], w[N];
ll dpL[N], dpR[N], ans[N];
int main(){
scanf("%d%d", &n, &q);
for(int i = 0;i < n;i++)
scanf("%lld", A + i);
for(int i = 1;i <= q;i++)
scanf("%lld", w + i);
ll cur = 0;
for(int i = 1;i <= q;i++){
cur += w[i];
dpL[i] = min(dpL[i - 1], cur);
dpR[i] = max(dpR[i - 1], cur);
}
ans[0] -= dpL[q]; ans[n - 1] += dpR[q];
for(int i = 0;i + 1 < n;i++){
ll raz = A[i + 1] - A[i];
int j = 0;
for(int k = 17;k >= 0;k--){
if(j + (1 << k) > q) continue;
if(-dpL[j + (1 << k)] + dpR[j + (1 << k)] <= raz)
j += (1 << k);
}
ans[i] += dpR[j];
ans[i + 1] -= dpL[j];
if(j < q){
if(w[j + 1] > 0)
ans[i] += raz + dpL[j] - dpR[j];
else
ans[i + 1] += raz + dpL[j] - dpR[j];
}
}
for(int i = 0;i < n;i++)
printf("%lld\n", ans[i]);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |