#include <bits/stdc++.h>
#define int long long
using namespace std;
map<pair<int,int>,int> to;
struct node{
int max,min,ans;
};
const int N = 2e5, inf = 1e17;
node segt[4*N+5];
int lazy[4*N+5];
node merge(node a, node b){
node c;
c.ans = max({a.ans,b.ans,a.max-b.min});
c.max = max(a.max,b.max);
c.min = min(a.min,b.min);
return c;
}
void update(int idx, int l, int r, int L, int R, int val){
if (l > R or r < L) return;
if (l >= L and r <= R){
if (L == R) segt[idx] = {val+lazy[idx],val+lazy[idx],0};
else{
segt[idx].max += val;
segt[idx].min += val;
lazy[idx] += val;
}
return;
}
for (int k:{2*idx,2*idx+1}){
segt[k].min += lazy[idx];
segt[k].max += lazy[idx];
lazy[k] += lazy[idx];
}
lazy[idx] = 0;
int mid = (l+r)/2;
update(2*idx,l,mid,L,R,val);
update(2*idx+1,mid+1,r,L,R,val);
segt[idx] = merge(segt[2*idx],segt[2*idx+1]);
}
node query(int idx, int l, int r, int L, int R){
if (r < L or l > R) return {-inf,inf,-inf};
if (l >= L and r <= R) return segt[idx];
for (int k:{2*idx,2*idx+1}){
segt[k].min += lazy[idx];
segt[k].max += lazy[idx];
lazy[k] += lazy[idx];
}
lazy[idx] = 0;
int mid = (l+r)/2;
return merge(query(2*idx,l,mid,L,R),query(2*idx+1,mid+1,r,L,R));
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,m,d;
cin >> n >> m >> d;
fill_n(segt,4*N+5,node{-inf,inf,-inf});
vector<int> init;
vector<pair<int,int>> a(n+m);
for (int i=0; i<n; ++i){
int pos;
cin >> pos;
a[i] = {pos,i};
init.emplace_back(pos);
}
vector<int> req;
for (int k=0; k<m; ++k){
int pos;
cin >> pos;
a[n+k] = {pos,n+k};
req.emplace_back(pos);
}
sort(a.begin(),a.end());
for (int i=0; i<n+m; ++i) to[a[i]] = i;
for (int i=0; i<n; ++i){
int pos = to[make_pair(init[i],i)];
update(1,0,n+m+4,pos,pos,init[i]);
update(1,0,n+m+4,pos+1,n+m+4,-d);
}
for (int i=0; i<m; ++i){
int pos = to[make_pair(req[i],i+n)];
update(1,0,n+m+4,pos,pos,req[i]);
update(1,0,n+m+4,pos+1,n+m+4,-d);
node ans = query(1,0,n+m+4,0,n+m+4);
cout << ans.ans/2;
if (ans.ans&1) cout << ".5";
cout << ' ';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
19308 KB |
Output is correct |
2 |
Correct |
10 ms |
19284 KB |
Output is correct |
3 |
Correct |
10 ms |
19332 KB |
Output is correct |
4 |
Correct |
11 ms |
19288 KB |
Output is correct |
5 |
Correct |
11 ms |
19284 KB |
Output is correct |
6 |
Correct |
11 ms |
19284 KB |
Output is correct |
7 |
Correct |
11 ms |
19236 KB |
Output is correct |
8 |
Correct |
10 ms |
19284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
19308 KB |
Output is correct |
2 |
Correct |
10 ms |
19284 KB |
Output is correct |
3 |
Correct |
10 ms |
19332 KB |
Output is correct |
4 |
Correct |
11 ms |
19288 KB |
Output is correct |
5 |
Correct |
11 ms |
19284 KB |
Output is correct |
6 |
Correct |
11 ms |
19284 KB |
Output is correct |
7 |
Correct |
11 ms |
19236 KB |
Output is correct |
8 |
Correct |
10 ms |
19284 KB |
Output is correct |
9 |
Correct |
532 ms |
42264 KB |
Output is correct |
10 |
Correct |
630 ms |
42308 KB |
Output is correct |
11 |
Correct |
294 ms |
42308 KB |
Output is correct |
12 |
Correct |
294 ms |
42368 KB |
Output is correct |
13 |
Correct |
264 ms |
41872 KB |
Output is correct |
14 |
Correct |
284 ms |
42304 KB |
Output is correct |
15 |
Correct |
480 ms |
41604 KB |
Output is correct |
16 |
Correct |
269 ms |
42252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
298 ms |
43336 KB |
Output is correct |
2 |
Correct |
296 ms |
45304 KB |
Output is correct |
3 |
Correct |
306 ms |
45396 KB |
Output is correct |
4 |
Correct |
298 ms |
43232 KB |
Output is correct |
5 |
Correct |
297 ms |
44412 KB |
Output is correct |
6 |
Correct |
293 ms |
43524 KB |
Output is correct |
7 |
Correct |
288 ms |
44552 KB |
Output is correct |
8 |
Correct |
286 ms |
43228 KB |
Output is correct |
9 |
Correct |
295 ms |
43088 KB |
Output is correct |
10 |
Correct |
332 ms |
45524 KB |
Output is correct |
11 |
Correct |
290 ms |
43892 KB |
Output is correct |
12 |
Correct |
291 ms |
44920 KB |
Output is correct |
13 |
Correct |
289 ms |
43168 KB |
Output is correct |
14 |
Correct |
281 ms |
45148 KB |
Output is correct |
15 |
Correct |
293 ms |
44848 KB |
Output is correct |
16 |
Correct |
289 ms |
42648 KB |
Output is correct |
17 |
Correct |
288 ms |
44428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
298 ms |
43336 KB |
Output is correct |
2 |
Correct |
296 ms |
45304 KB |
Output is correct |
3 |
Correct |
306 ms |
45396 KB |
Output is correct |
4 |
Correct |
298 ms |
43232 KB |
Output is correct |
5 |
Correct |
297 ms |
44412 KB |
Output is correct |
6 |
Correct |
293 ms |
43524 KB |
Output is correct |
7 |
Correct |
288 ms |
44552 KB |
Output is correct |
8 |
Correct |
286 ms |
43228 KB |
Output is correct |
9 |
Correct |
295 ms |
43088 KB |
Output is correct |
10 |
Correct |
332 ms |
45524 KB |
Output is correct |
11 |
Correct |
290 ms |
43892 KB |
Output is correct |
12 |
Correct |
291 ms |
44920 KB |
Output is correct |
13 |
Correct |
289 ms |
43168 KB |
Output is correct |
14 |
Correct |
281 ms |
45148 KB |
Output is correct |
15 |
Correct |
293 ms |
44848 KB |
Output is correct |
16 |
Correct |
289 ms |
42648 KB |
Output is correct |
17 |
Correct |
288 ms |
44428 KB |
Output is correct |
18 |
Correct |
568 ms |
43512 KB |
Output is correct |
19 |
Correct |
550 ms |
45240 KB |
Output is correct |
20 |
Correct |
334 ms |
45396 KB |
Output is correct |
21 |
Correct |
320 ms |
43332 KB |
Output is correct |
22 |
Correct |
423 ms |
43596 KB |
Output is correct |
23 |
Correct |
301 ms |
43460 KB |
Output is correct |
24 |
Correct |
525 ms |
44060 KB |
Output is correct |
25 |
Correct |
289 ms |
43104 KB |
Output is correct |
26 |
Correct |
568 ms |
43120 KB |
Output is correct |
27 |
Correct |
598 ms |
45628 KB |
Output is correct |
28 |
Correct |
421 ms |
43548 KB |
Output is correct |
29 |
Correct |
516 ms |
44900 KB |
Output is correct |
30 |
Correct |
336 ms |
43036 KB |
Output is correct |
31 |
Correct |
339 ms |
45144 KB |
Output is correct |
32 |
Correct |
328 ms |
44832 KB |
Output is correct |
33 |
Correct |
549 ms |
42740 KB |
Output is correct |
34 |
Correct |
328 ms |
44424 KB |
Output is correct |