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;
#define int long long
struct Fenwick {
int n;
vector<int> fw;
Fenwick(int _n) {
n = _n;
fw.resize(n);
for(int i = 0; i < n; i++) fw[i] = 0;
}
void update(int x) { for(int i = x; i < n; i += (i & -i)) fw[i]++; }
int get(int r) {
int ans = 0;
for(int i = r; i >= 1; i -= (i & -i)) ans += fw[i];
return ans;
}
};
const long long inf = 1e18;
struct node {
long long mx;
long long mn;
long long ans;
long long lzy;
node() {
mx = -inf;
mn = inf;
ans = 0;
lzy = 0;
}
};
const int N = 2e5 + 20;
int n, m, D;
int a[N];
node st[4 * N];
vector<int> all;
int toa[N], tob[N];
int order[N];
int to[N];
int ind[N];
Fenwick fw(N);
node mrg(node L, node R) {
node nd;
nd.mx = max(L.mx, R.mx);
nd.mn = min(L.mn, R.mn);
nd.ans = max({L.ans, R.ans, L.mx - R.mn});
nd.lzy = 0;
return nd;
}
void propagate(int index) {
if(2 * index + 1 < 4 * N) {
st[2 * index].mx += st[index].lzy;
st[2 * index].mn += st[index].lzy;
st[2 * index].lzy += st[index].lzy;
st[2 * index + 1].mx += st[index].lzy;
st[2 * index + 1].mn += st[index].lzy;
st[2 * index + 1].lzy += st[index].lzy;
st[index].lzy = 0;
}
}
void update(int index, int l, int r, int L, int R, int val) {
if(l > r || r < L || R < l) return;
if(L <= l && r <= R) {
st[index].mx += val;
st[index].mn += val;
st[index].lzy += val;
return;
}
int mid = (l + r) / 2;
propagate(index);
update(2 * index, l, mid, L, R, val);
update(2 * index + 1, mid + 1, r, L, R, val);
st[index] = mrg(st[2 * index], st[2 * index + 1]);
}
void modify(int index, int l, int r, int x, int val) {
if(l > r || r < x || x < l) return;
if(l == r) {
st[index].mx = st[index].mn = val;
st[index].ans = 0;
return;
}
int mid = (l + r) / 2;
propagate(index);
modify(2 * index, l, mid, x, val);
modify(2 * index + 1, mid + 1, r, x, val);
st[index] = mrg(st[2 * index], st[2 * index + 1]);
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> D;
n += m;
for(int i = 1; i <= n; i++) {
cin >> a[i];
order[i] = i;
}
sort(order + 1, order + n + 1, [&](int i, int j) { return a[i] < a[j]; });
for(int i = 1; i <= n; i++) to[order[i]] = i;
for(int qind = 1; qind <= n; qind++) {
fw.update(to[qind]);
update(1, 1, n, to[qind] + 1, n, -D);
modify(1, 1, n, to[qind], a[qind] - D * 1LL * fw.get(to[qind] - 1));
if(qind <= n - m) continue;
// cout << fw.get(to[qind] - 1) << " ";
// cout << st[1].mx << " " << st[1].mn << "\n";
cout << st[1].ans / 2 << (st[1].ans % 2 == 1 ? ".5 " : " ");
}
return 0;
}
# | 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... |