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>
#define int long long
#define mid ((deb + fin) >> 1)
using namespace std;
const int M = 1 << 18, N = 2 * M, INF = 1e18 + 42;
struct Node {
int mini, maxi, maxDiff, lazy, nb;
} node[N];
pair<int, int> pii[M];
int n, m, d, a[N], id[M];
inline void applyOp(int i, int add) {
node[i].mini += add;
node[i].maxi += add;
node[i].lazy += add;
}
inline void upd(int i) {
node[i].mini = INF;
node[i].maxi = -INF;
node[i].maxDiff = 0;
for(int child : {i*2, i*2+1})
if(node[child].nb) {
node[i].mini = min(node[i].mini, node[child].mini);
node[i].maxi = max(node[i].maxi, node[child].maxi);
node[i].maxDiff = max(node[i].maxDiff, node[child].maxDiff);
}
if(node[i*2].nb && node[i*2+1].nb)
node[i].maxDiff = max(node[i].maxDiff, node[i*2].maxi - node[i*2+1].mini);
}
inline void propage(int i) {
applyOp(i*2, node[i].lazy);
applyOp(i*2+1, node[i].lazy);
node[i].lazy = 0;
}
void update(int i, int deb, int fin, int l, int r, int add, int nouv) {
if(fin <= l || r <= deb) return;
if(nouv == 0 && l <= deb && fin <= r) {
applyOp(i, add);
return;
}
if(nouv) node[i].nb++;
if(fin - deb == 1 && deb == l) {
node[i].mini += nouv;
node[i].maxi += nouv;
return;
}
propage(i);
update(i*2, deb, mid, l, r, add, nouv);
update(i*2+1, mid, fin, l, r, add, nouv);
upd(i);
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> d;
for(int i = 0; i < n + m; i++) {
cin >> a[i];
pii[i].first = a[i];
pii[i].second = i;
}
sort(pii, pii + n + m);
for(int i = 0; i < n + m; i++)
id[pii[i].second] = i;
for(int i = 0; i < n + m; i++) {
update(1, 0, M, id[i], id[i]+1, 0, a[i]);
update(1, 0, M, id[i]+1, M, -d, 0);
if(i >= n) {
if(node[1].maxDiff % 2 == 1) cout << node[1].maxDiff / 2 << ".5 ";
else cout << node[1].maxDiff / 2 << ' ';
}
}
cout << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |