1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| #include<bits/stdc++.h> #define inf 0x3f3f3f3f3f3f3f3fll using namespace std; using ll=long long; inline int read() { int s=0,w=1;char ch; while((ch=getchar())>'9'||ch<'0') if(ch=='-') w=-1; while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar(); return s*w; } struct node { int id; int x; }a[400001]; ll num[1600001]; ll ma[1600001]; ll mi[1600001]; ll c[1600001]; int t[400001]; int w[400001]; int x[400001]; int n,m,d; int cnt; void build(int p,int pl,int pr) { num[p]=-inf,ma[p]=-inf,mi[p]=inf; if(pl==pr) return ; int mid=(pl+pr)>>1; build(p*2,pl,mid); build(p*2|1,mid+1,pr); } inline void push_up(int p) { c[p]=c[p*2]+c[p*2|1]; ma[p]=max(ma[p*2],ma[p*2|1]-d*c[p*2]); mi[p]=min(mi[p*2],mi[p*2|1]-d*c[p*2]); num[p]=max(max(num[p*2],num[p*2|1]),ma[p*2]-(mi[p*2|1]-c[p*2]*d)); } void change(int p,int pl,int pr,int x,int y) { if(pl==pr) { mi[p]=ma[p]=y; c[p]=1,num[p]=0; return ; } int mid=(pl+pr)>>1; if(x<=mid) change(p*2,pl,mid,x,y); else change(p*2|1,mid+1,pr,x,y); push_up(p); } inline void solve() { build(1,1,n+m); for(int i=1;i<=n+m;i++) { change(1,1,n+m,w[i],x[i]);
if(i>n) { ll ans=max(num[1],0ll); if(num[1]&1) printf("%lld.5 ",ans/2); else printf("%lld ",ans/2); } } } int main() { n=read(),m=read(),d=read(); for(int i=1;i<=n+m;i++) { a[i].x=x[i]=read(); a[i].id=i; } sort(a+1,a+n+m+1,[](node a,node b){ return a.x<b.x;}); for(int i=1;i<=n+m;i++) w[a[i].id]=i; solve(); return 0; }
|