#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif
using ll=long long;
const int N=222222;
int n,m,k,c[N],cnt[N],v[N];
ll d,a[N],b[N];
struct Seg{
struct node{
ll cnt=0,mn=0,mx=0,res=0;
}T[2*N];
node mrg(node L,node R){
if(!L.cnt) return R;
if(!R.cnt) return L;
node ret;
ret.cnt=L.cnt+R.cnt;
ret.mn=min(L.mn,R.mn+L.cnt*d);
ret.mx=max(L.mx,R.mx+L.cnt*d);
ret.res=max({0ll,L.res,R.res,R.mx+L.cnt*d-L.mn});
return ret;
}
void upd(int nd,int l,int r,int x){
if(l==r){
T[nd].cnt=1;
T[nd].mn=T[nd].mx=d-v[x];
return;
}
int m=(l+r)>>1,ln=nd+1,rn=nd+2*(m-l+1);
if(x<=m) upd(ln,l,m,x);
else upd(rn,m+1,r,x);
T[nd]=mrg(T[ln],T[rn]);
}
}T;
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>m>>d;
for(int i=1;i<=n;i++){
cin>>a[i];
c[i]=a[i];
}
for(int i=1;i<=m;i++){
cin>>b[i];
c[i+n]=b[i];
}
sort(c+1,c+n+m+1);
k=unique(c+1,c+n+m+1)-c-1;
for(int i=1;i<=n;i++){
a[i]=lower_bound(c+1,c+k+1,a[i])-c;
cnt[a[i]]++;
}
for(int i=1;i<=m;i++){
b[i]=lower_bound(c+1,c+k+1,b[i])-c;
cnt[b[i]]++;
}
for(int i=1;i<=k;i++){
cnt[i]+=cnt[i-1];
for(int j=cnt[i-1]+1;j<=cnt[i];j++) v[j]=c[i];
}
for(int i=1;i<=n;i++) a[i]=cnt[a[i]]--;
for(int i=1;i<=m;i++) b[i]=cnt[b[i]]--;
for(int i=1;i<=n;i++) T.upd(1,1,n+m,a[i]);
for(int i=1;i<=m;i++){
T.upd(1,1,n+m,b[i]);
ll ans=T.T[1].res;
if(ans%2==0) cout<<ans/2<<" ";
else cout<<ans/2<<".5 ";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
7 |
Correct |
1 ms |
6748 KB |
Output is correct |
8 |
Correct |
1 ms |
6748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
7 |
Correct |
1 ms |
6748 KB |
Output is correct |
8 |
Correct |
1 ms |
6748 KB |
Output is correct |
9 |
Correct |
88 ms |
20052 KB |
Output is correct |
10 |
Correct |
86 ms |
20200 KB |
Output is correct |
11 |
Correct |
38 ms |
19796 KB |
Output is correct |
12 |
Correct |
64 ms |
20048 KB |
Output is correct |
13 |
Correct |
40 ms |
20052 KB |
Output is correct |
14 |
Correct |
49 ms |
20172 KB |
Output is correct |
15 |
Correct |
81 ms |
20200 KB |
Output is correct |
16 |
Correct |
45 ms |
20052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
21128 KB |
Output is correct |
2 |
Correct |
57 ms |
23124 KB |
Output is correct |
3 |
Correct |
50 ms |
22608 KB |
Output is correct |
4 |
Correct |
54 ms |
20820 KB |
Output is correct |
5 |
Correct |
54 ms |
22096 KB |
Output is correct |
6 |
Correct |
50 ms |
21328 KB |
Output is correct |
7 |
Correct |
54 ms |
22304 KB |
Output is correct |
8 |
Correct |
51 ms |
21008 KB |
Output is correct |
9 |
Correct |
53 ms |
20820 KB |
Output is correct |
10 |
Correct |
58 ms |
23380 KB |
Output is correct |
11 |
Correct |
52 ms |
21840 KB |
Output is correct |
12 |
Correct |
54 ms |
22612 KB |
Output is correct |
13 |
Correct |
57 ms |
20840 KB |
Output is correct |
14 |
Correct |
54 ms |
22868 KB |
Output is correct |
15 |
Correct |
55 ms |
22624 KB |
Output is correct |
16 |
Correct |
49 ms |
20964 KB |
Output is correct |
17 |
Correct |
54 ms |
22356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
21128 KB |
Output is correct |
2 |
Correct |
57 ms |
23124 KB |
Output is correct |
3 |
Correct |
50 ms |
22608 KB |
Output is correct |
4 |
Correct |
54 ms |
20820 KB |
Output is correct |
5 |
Correct |
54 ms |
22096 KB |
Output is correct |
6 |
Correct |
50 ms |
21328 KB |
Output is correct |
7 |
Correct |
54 ms |
22304 KB |
Output is correct |
8 |
Correct |
51 ms |
21008 KB |
Output is correct |
9 |
Correct |
53 ms |
20820 KB |
Output is correct |
10 |
Correct |
58 ms |
23380 KB |
Output is correct |
11 |
Correct |
52 ms |
21840 KB |
Output is correct |
12 |
Correct |
54 ms |
22612 KB |
Output is correct |
13 |
Correct |
57 ms |
20840 KB |
Output is correct |
14 |
Correct |
54 ms |
22868 KB |
Output is correct |
15 |
Correct |
55 ms |
22624 KB |
Output is correct |
16 |
Correct |
49 ms |
20964 KB |
Output is correct |
17 |
Correct |
54 ms |
22356 KB |
Output is correct |
18 |
Correct |
91 ms |
21328 KB |
Output is correct |
19 |
Correct |
107 ms |
23020 KB |
Output is correct |
20 |
Correct |
54 ms |
22660 KB |
Output is correct |
21 |
Correct |
73 ms |
21076 KB |
Output is correct |
22 |
Correct |
83 ms |
21312 KB |
Output is correct |
23 |
Correct |
57 ms |
21332 KB |
Output is correct |
24 |
Correct |
94 ms |
21868 KB |
Output is correct |
25 |
Correct |
56 ms |
20916 KB |
Output is correct |
26 |
Correct |
93 ms |
20816 KB |
Output is correct |
27 |
Correct |
97 ms |
23376 KB |
Output is correct |
28 |
Correct |
73 ms |
21368 KB |
Output is correct |
29 |
Correct |
84 ms |
22640 KB |
Output is correct |
30 |
Correct |
72 ms |
20820 KB |
Output is correct |
31 |
Correct |
75 ms |
22868 KB |
Output is correct |
32 |
Correct |
60 ms |
22760 KB |
Output is correct |
33 |
Correct |
93 ms |
20960 KB |
Output is correct |
34 |
Correct |
76 ms |
22352 KB |
Output is correct |