#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll base = 1<<19;
ll inf = 1e18;
vector<ll> T(2*base,0), mi(2*base,inf), ma(2*base,-inf), lazy(2*base,0); // answer, max value K[x], min value K[x]
void merge(ll v, ll l, ll r) { // Calculates max over i < j of K[j] - K[i] where K[x] = D*x + pos
T[v] = max(T[l], T[r]);
T[v] = max(T[v], ma[r] - mi[l]);
ma[v] = max(ma[r], ma[l]);
mi[v] = min(mi[r], mi[l]);
}
ll D;
void push(int v, int l, int r) {
if(!lazy[v] || v >= base) return;
for(auto x : {l,r}) {
ma[x] += lazy[v];
mi[x] += lazy[v];
lazy[x] += lazy[v];
}
lazy[v] = 0;
}
void update(int v, int a, int b, int p, int k, int val, bool ustaw) {
if(b < p || k < a) return;
if(p<=a && b<=k) {
if(ustaw) {
mi[v] = ma[v] = val;
T[v] = lazy[v] = 0;
} else {
mi[v] += val;
ma[v] += val;
lazy[v] += val;
}
return;
}
int l =2*v; int r=l+1; int mid = (a+b)/2;
push(v,l,r);
update(l,a,mid,p,k,val,ustaw);
update(r,mid+1,b,p,k,val,ustaw);
merge(v,l,r);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll n, m;
cin >> n >> m >> D;
vector<ll> x(n), y(m);
for(ll i=0; i<n; ++i) cin >> x[i];
for(ll i=0; i<m; ++i) cin >> y[i];
vector<pair<ll, ll>> pary;
for(ll i=0; i<n; ++i) {
pary.push_back({x[i], i});
}
for(ll i=0; i<m; ++i) {
pary.push_back({y[i], i+n});
}
sort(pary.begin(), pary.end());
ll cnt = 0;
vector<ll> idx(n+m);
ordered_set<ll> os;
for(auto[a,b] : pary) {
idx[b] = cnt++;
}
for(ll i=0; i<n; ++i) {
os.insert(idx[i]);
update(1,0,base-1, idx[i], idx[i], D*os.order_of_key(idx[i]) - x[i], 1);
update(1,0,base-1, idx[i]+1, base-1, D, 0);
}
for(ll i=0; i<m; ++i) {
os.insert(idx[i+n]);
update(1,0,base-1, idx[i+n], idx[i+n], D*os.order_of_key(idx[i+n]) - y[i], 1);
update(1,0,base-1, idx[i+n]+1, base-1, D, 0);
cout << T[1]/2;
if(T[1]%2==1) cout << ".5";
cout << " ";
}
cout << "\n";
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... |