#include <bits/stdc++.h>
#define int long long
using namespace std;
const int M = 1 << 18, N = 2 * M, INF = 1e18 + 42;
struct Node {
int mini, maxi, maxDiff, lazy, nb;
} node[N];
pair<int, int> pii[N];
int n, m, d, a[N], id[N];
void applyOp(int i, int add) {
node[i].mini += add;
node[i].maxi += add;
node[i].lazy += add;
}
void upd(int i) {
node[i].mini = INF;
node[i].maxi = -INF;
node[i].maxDiff = 0;
if(node[i*2].nb) {
node[i].mini = min(node[i].mini, node[i*2].mini);
node[i].maxi = max(node[i].maxi, node[i*2].maxi);
node[i].maxDiff = max(node[i].maxDiff, node[i*2].maxDiff);
}
if(node[i*2+1].nb) {
node[i].mini = min(node[i].mini, node[i*2+1].mini);
node[i].maxi = max(node[i].maxi, node[i*2+1].maxi);
node[i].maxDiff = max(node[i].maxDiff, node[i*2+1].maxDiff);
}
if(node[i*2].nb && node[i*2+1].nb)
node[i].maxDiff = max(node[i].maxDiff, node[i*2].maxi - node[i*2+1].mini);
}
void propage(int i) {
applyOp(i*2, node[i].lazy);
applyOp(i*2+1, node[i].lazy);
node[i].lazy = 0;
}
void addNew(int i, int deb, int fin, int p, int val) {
if(fin <= p || p < deb) return;
if(fin - deb == 1 && deb == p) {
node[i].nb = 1;
node[i].lazy = 0;
node[i].mini += val;
node[i].maxi += val;
return;
}
propage(i);
int mid = ((deb + fin) >> 1);
addNew(i*2, deb, mid, p, val);
addNew(i*2+1, mid, fin, p, val);
node[i].nb = node[i*2].nb + node[i*2+1].nb;
upd(i);
}
void update(int i, int deb, int fin, int l, int r, int add) {
if(fin <= l || r <= deb) return;
if(l <= deb && fin <= r) {
applyOp(i, add);
return;
}
propage(i);
int mid = ((deb + fin) >> 1);
update(i*2, deb, mid, l, r, add);
update(i*2+1, mid, fin, l, r, add);
upd(i);
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> d;
for(int i = 0; i < n + m; i++) {
cin >> a[i];
pii[i].first = a[i];
pii[i].second = i;
}
sort(pii, pii + n + m);
for(int i = 0; i < n + m; i++)
id[pii[i].second] = i;
for(int i = 0; i < n + m; i++) {
addNew(1, 0, M, id[i], a[i]);
update(1, 0, M, id[i]+1, M, -d);
if(i >= n) {
if(node[1].maxDiff % 2 == 1) cout << node[1].maxDiff / 2 << ".5 ";
else cout << node[1].maxDiff / 2 << ' ';
}
}
cout << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
3 ms |
596 KB |
Output is correct |
3 |
Correct |
3 ms |
624 KB |
Output is correct |
4 |
Correct |
3 ms |
596 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
4 ms |
592 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
3 ms |
596 KB |
Output is correct |
3 |
Correct |
3 ms |
624 KB |
Output is correct |
4 |
Correct |
3 ms |
596 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
4 ms |
592 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
260 ms |
22752 KB |
Output is correct |
10 |
Correct |
203 ms |
24140 KB |
Output is correct |
11 |
Correct |
133 ms |
24360 KB |
Output is correct |
12 |
Correct |
165 ms |
24156 KB |
Output is correct |
13 |
Correct |
177 ms |
23756 KB |
Output is correct |
14 |
Correct |
141 ms |
24096 KB |
Output is correct |
15 |
Correct |
200 ms |
23500 KB |
Output is correct |
16 |
Correct |
137 ms |
24316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
151 ms |
23688 KB |
Output is correct |
2 |
Correct |
182 ms |
27156 KB |
Output is correct |
3 |
Correct |
160 ms |
27180 KB |
Output is correct |
4 |
Correct |
155 ms |
24892 KB |
Output is correct |
5 |
Correct |
169 ms |
26220 KB |
Output is correct |
6 |
Correct |
155 ms |
25272 KB |
Output is correct |
7 |
Correct |
154 ms |
26276 KB |
Output is correct |
8 |
Correct |
172 ms |
25032 KB |
Output is correct |
9 |
Correct |
151 ms |
24908 KB |
Output is correct |
10 |
Correct |
159 ms |
27328 KB |
Output is correct |
11 |
Correct |
148 ms |
25700 KB |
Output is correct |
12 |
Correct |
161 ms |
26740 KB |
Output is correct |
13 |
Correct |
158 ms |
24908 KB |
Output is correct |
14 |
Correct |
165 ms |
26956 KB |
Output is correct |
15 |
Correct |
167 ms |
26680 KB |
Output is correct |
16 |
Correct |
143 ms |
24532 KB |
Output is correct |
17 |
Correct |
165 ms |
26188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
151 ms |
23688 KB |
Output is correct |
2 |
Correct |
182 ms |
27156 KB |
Output is correct |
3 |
Correct |
160 ms |
27180 KB |
Output is correct |
4 |
Correct |
155 ms |
24892 KB |
Output is correct |
5 |
Correct |
169 ms |
26220 KB |
Output is correct |
6 |
Correct |
155 ms |
25272 KB |
Output is correct |
7 |
Correct |
154 ms |
26276 KB |
Output is correct |
8 |
Correct |
172 ms |
25032 KB |
Output is correct |
9 |
Correct |
151 ms |
24908 KB |
Output is correct |
10 |
Correct |
159 ms |
27328 KB |
Output is correct |
11 |
Correct |
148 ms |
25700 KB |
Output is correct |
12 |
Correct |
161 ms |
26740 KB |
Output is correct |
13 |
Correct |
158 ms |
24908 KB |
Output is correct |
14 |
Correct |
165 ms |
26956 KB |
Output is correct |
15 |
Correct |
167 ms |
26680 KB |
Output is correct |
16 |
Correct |
143 ms |
24532 KB |
Output is correct |
17 |
Correct |
165 ms |
26188 KB |
Output is correct |
18 |
Correct |
232 ms |
25300 KB |
Output is correct |
19 |
Correct |
234 ms |
27008 KB |
Output is correct |
20 |
Correct |
171 ms |
27124 KB |
Output is correct |
21 |
Correct |
184 ms |
25168 KB |
Output is correct |
22 |
Correct |
205 ms |
25420 KB |
Output is correct |
23 |
Correct |
200 ms |
25280 KB |
Output is correct |
24 |
Correct |
234 ms |
25828 KB |
Output is correct |
25 |
Correct |
155 ms |
24916 KB |
Output is correct |
26 |
Correct |
265 ms |
24916 KB |
Output is correct |
27 |
Correct |
282 ms |
27376 KB |
Output is correct |
28 |
Correct |
208 ms |
25420 KB |
Output is correct |
29 |
Correct |
256 ms |
26676 KB |
Output is correct |
30 |
Correct |
219 ms |
24908 KB |
Output is correct |
31 |
Correct |
225 ms |
26856 KB |
Output is correct |
32 |
Correct |
228 ms |
26840 KB |
Output is correct |
33 |
Correct |
264 ms |
24588 KB |
Output is correct |
34 |
Correct |
207 ms |
26336 KB |
Output is correct |