#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long
#define en cin.close();return 0;
#define pb push_back
#define fi first//printf("%lli\n",cur);
#define se second//scanf("%lli",&n);
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 2e5+15;
const ll INF = 1e18;
struct node
{
ll mi = INF, mx = -INF, cnt = 0, lzy = 0;
};
node segt[4*N];
int mx;
void updlzy(int pos, int siz)
{
ll lzy = segt[pos].lzy;
if(lzy)
{
segt[pos].mi+=lzy;
segt[pos].mx+=lzy;
if(siz>1)
segt[pos*2].lzy+=lzy,
segt[pos*2+1].lzy+=lzy;
segt[pos].lzy=0;
}
}
void updnode(int pos)
{
segt[pos].cnt=segt[pos*2].cnt+segt[pos*2+1].cnt;
segt[pos].mi=min(segt[pos*2].mi,segt[pos*2+1].mi);
segt[pos].mx=max(segt[pos*2].mx,segt[pos*2+1].mx);
}
void upd(int lb, int rb, ll val, int l = 0, int r = mx, int pos = 1)
{
updlzy(pos,r-l+1);
if(rb<l||r<lb)
return;
if(lb<=l&&r<=rb)
segt[pos].lzy+=val,
updlzy(pos,r-l+1);
else
{
int mid = (l+r)/2;
upd(lb,rb,val,l,mid,pos*2);
upd(lb,rb,val,mid+1,r,pos*2+1);
updnode(pos);
}
}
void setupd(int p, ll val, int sz, int l = 0, int r = mx, int pos = 1)
{
updlzy(pos,r-l+1);
if(l==r)
segt[pos].mi=segt[pos].mx=val,
segt[pos].cnt=sz;
else
{
int mid = (l+r)/2;
if(p<=mid)
setupd(p,val,sz,l,mid,pos*2),
updlzy(pos*2+1,r-mid);
else
setupd(p,val,sz,mid+1,r,pos*2+1),
updlzy(pos*2,mid-l+1);
updnode(pos);
}
}
node get1(int lb, int rb, int l = 0, int r = mx, int pos = 1)
{
updlzy(pos,r-l+1);
if(rb<l||r<lb)
return {INF,-INF,0};
if(lb<=l&&r<=rb)
return segt[pos];
int mid = (l+r)/2;
auto t1 = get1(lb,rb,l,mid,pos*2), t2 = get1(lb,rb,mid+1,r,pos*2+1);
return {min(t1.mi,t2.mi),max(t1.mx,t2.mx),t1.cnt+t2.cnt};
}
int main()
{
fio
// ifstream cin("in.in");
int n, m, d;
cin >> n >> m >> d;
mx=n+m-1;
vector<pair<int,int> > a(n+m);
for(int i = 0;i<n+m;i++)
cin >> a[i].fi,
a[i].se=i;
sort(a.begin(),a.end());
vector<int> ord(n+m);
for(int i = 0;i<n+m;i++)
ord[a[i].se]=i;
ll res = 0;
for(int i = 0;i<n+m;i++)
{
int val = a[ord[i]].fi, pos = ord[i];
ll cur = d*get1(0,pos).cnt-val;
setupd(pos,cur,1);
upd(pos+1,n+m-1,d);
res=max(res,get1(pos,n+m-1).mx-get1(0,pos-1).mi);
res=max(res,get1(pos+1,n+m-1).mx-get1(0,pos).mi);
if(i>=n)
{
cout << res/2;
if(res%2)
cout << ".5";
cout << " ";
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
3 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
3 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
374 ms |
19100 KB |
Output is correct |
10 |
Correct |
413 ms |
19028 KB |
Output is correct |
11 |
Correct |
268 ms |
21012 KB |
Output is correct |
12 |
Correct |
327 ms |
20940 KB |
Output is correct |
13 |
Correct |
290 ms |
20492 KB |
Output is correct |
14 |
Correct |
297 ms |
20940 KB |
Output is correct |
15 |
Correct |
425 ms |
20232 KB |
Output is correct |
16 |
Correct |
285 ms |
21032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
320 ms |
20076 KB |
Output is correct |
2 |
Correct |
312 ms |
22072 KB |
Output is correct |
3 |
Correct |
324 ms |
21972 KB |
Output is correct |
4 |
Correct |
418 ms |
19820 KB |
Output is correct |
5 |
Correct |
334 ms |
21064 KB |
Output is correct |
6 |
Correct |
292 ms |
20212 KB |
Output is correct |
7 |
Correct |
307 ms |
21208 KB |
Output is correct |
8 |
Correct |
297 ms |
19916 KB |
Output is correct |
9 |
Correct |
348 ms |
19808 KB |
Output is correct |
10 |
Correct |
293 ms |
22168 KB |
Output is correct |
11 |
Correct |
293 ms |
20688 KB |
Output is correct |
12 |
Correct |
303 ms |
21644 KB |
Output is correct |
13 |
Correct |
329 ms |
19884 KB |
Output is correct |
14 |
Correct |
306 ms |
21784 KB |
Output is correct |
15 |
Correct |
305 ms |
21628 KB |
Output is correct |
16 |
Correct |
292 ms |
19800 KB |
Output is correct |
17 |
Correct |
308 ms |
21068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
320 ms |
20076 KB |
Output is correct |
2 |
Correct |
312 ms |
22072 KB |
Output is correct |
3 |
Correct |
324 ms |
21972 KB |
Output is correct |
4 |
Correct |
418 ms |
19820 KB |
Output is correct |
5 |
Correct |
334 ms |
21064 KB |
Output is correct |
6 |
Correct |
292 ms |
20212 KB |
Output is correct |
7 |
Correct |
307 ms |
21208 KB |
Output is correct |
8 |
Correct |
297 ms |
19916 KB |
Output is correct |
9 |
Correct |
348 ms |
19808 KB |
Output is correct |
10 |
Correct |
293 ms |
22168 KB |
Output is correct |
11 |
Correct |
293 ms |
20688 KB |
Output is correct |
12 |
Correct |
303 ms |
21644 KB |
Output is correct |
13 |
Correct |
329 ms |
19884 KB |
Output is correct |
14 |
Correct |
306 ms |
21784 KB |
Output is correct |
15 |
Correct |
305 ms |
21628 KB |
Output is correct |
16 |
Correct |
292 ms |
19800 KB |
Output is correct |
17 |
Correct |
308 ms |
21068 KB |
Output is correct |
18 |
Correct |
423 ms |
20260 KB |
Output is correct |
19 |
Correct |
406 ms |
21884 KB |
Output is correct |
20 |
Correct |
288 ms |
23936 KB |
Output is correct |
21 |
Correct |
351 ms |
21960 KB |
Output is correct |
22 |
Correct |
352 ms |
22280 KB |
Output is correct |
23 |
Correct |
309 ms |
22120 KB |
Output is correct |
24 |
Correct |
404 ms |
22640 KB |
Output is correct |
25 |
Correct |
276 ms |
21828 KB |
Output is correct |
26 |
Correct |
412 ms |
21728 KB |
Output is correct |
27 |
Correct |
397 ms |
24212 KB |
Output is correct |
28 |
Correct |
341 ms |
22220 KB |
Output is correct |
29 |
Correct |
378 ms |
23568 KB |
Output is correct |
30 |
Correct |
326 ms |
21712 KB |
Output is correct |
31 |
Correct |
336 ms |
23700 KB |
Output is correct |
32 |
Correct |
309 ms |
23612 KB |
Output is correct |
33 |
Correct |
392 ms |
21324 KB |
Output is correct |
34 |
Correct |
340 ms |
23068 KB |
Output is correct |