#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
const int N = 2e5 + 7;
const int INF = 1e16;
int n, m, d;
int a[2 * N], b[2 * N];
struct Node {
ll mn;
ll mx;
ll diff;
Node() {
mn = INF;
mx = -INF;
diff = 0;
}
};
Node operator + (Node a, Node b) {
Node c;
c.mn = min(a.mn, b.mn);
c.mx = max(a.mx, b.mx);
c.diff = max(a.diff, b.diff);
c.diff = max(c.diff, b.mx - a.mn);
return c;
}
Node tree[8 * N];
pair<ll, ll> lazy[8 * N];
void push(int v, int tl, int tr) {
if (tl < tr) {
lazy[2 * v].first += lazy[v].first;
lazy[2 * v].second += lazy[v].second;
lazy[2 * v + 1].first += lazy[v].first;
lazy[2 * v + 1].second += lazy[v].second;
}
tree[v].mn += lazy[v].first;
tree[v].mx += lazy[v].second;
lazy[v] = {0, 0};
}
void add(int v, int tl, int tr, int l, int r, ll x, ll y) {
push(v, tl, tr);
if (l > tr || r < tl) {
return;
}
if (l <= tl && tr <= r) {
lazy[v].first += x;
lazy[v].second += y;
push(v, tl, tr);
return;
}
int tm = (tl + tr) / 2;
add(2 * v, tl, tm, l, r, x, y);
add(2 * v + 1, tm + 1, tr, l, r, x, y);
tree[v] = tree[2 * v] + tree[2 * v + 1];
}
Node get(int v, int tl, int tr, int l, int r) {
push(v, tl, tr);
if (l <= tl && tr <= r) {
return tree[v];
}
int tm = (tl + tr) / 2;
if (l <= tm && r <= tm) {
return get(2 * v, tl, tm, l, r);
} else if (tm + 1 <= l && tm + 1 <= r) {
return get(2 * v + 1, tm + 1, tr, l, r);
} else {
return get(2 * v, tl, tm, l, tm) + get(2 * v + 1, tm + 1, tr, tm + 1, r);
}
}
ll ans = 0;
void baga(int i) {
add(1, 1, n + m, b[i], b[i], -(INF + a[i]), INF - a[i]);
add(1, 1, n + m, b[i], n + m, d, d);
ans = get(1, 1, n + m, 1, n + m).diff;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> d;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int i = 1; i <= m; ++i) {
cin >> a[i + n];
}
{
vector<pair<int, int>> v;
for (int i = 1; i <= n + m; ++i) v.push_back({a[i], i});
sort(v.begin(), v.end());
for (int i = 0; i < n + m; ++i) b[v[i].second] = i + 1;
}
for (int i = 1; i <= n; ++i) {
baga(i);
}
for (int i = 1; i <= m; ++i) {
baga(i + n);
cout << ans / 2;
if (ans % 2 == 1) cout << ".5";
cout << " ";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
38232 KB |
Output is correct |
2 |
Correct |
15 ms |
37980 KB |
Output is correct |
3 |
Correct |
16 ms |
37980 KB |
Output is correct |
4 |
Correct |
15 ms |
38100 KB |
Output is correct |
5 |
Correct |
16 ms |
37980 KB |
Output is correct |
6 |
Correct |
16 ms |
38180 KB |
Output is correct |
7 |
Correct |
17 ms |
37976 KB |
Output is correct |
8 |
Correct |
17 ms |
37980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
38232 KB |
Output is correct |
2 |
Correct |
15 ms |
37980 KB |
Output is correct |
3 |
Correct |
16 ms |
37980 KB |
Output is correct |
4 |
Correct |
15 ms |
38100 KB |
Output is correct |
5 |
Correct |
16 ms |
37980 KB |
Output is correct |
6 |
Correct |
16 ms |
38180 KB |
Output is correct |
7 |
Correct |
17 ms |
37976 KB |
Output is correct |
8 |
Correct |
17 ms |
37980 KB |
Output is correct |
9 |
Correct |
214 ms |
51408 KB |
Output is correct |
10 |
Correct |
201 ms |
51344 KB |
Output is correct |
11 |
Correct |
157 ms |
51316 KB |
Output is correct |
12 |
Correct |
210 ms |
51344 KB |
Output is correct |
13 |
Correct |
153 ms |
50804 KB |
Output is correct |
14 |
Correct |
160 ms |
51316 KB |
Output is correct |
15 |
Correct |
209 ms |
50800 KB |
Output is correct |
16 |
Correct |
152 ms |
51220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
197 ms |
52332 KB |
Output is correct |
2 |
Correct |
174 ms |
54256 KB |
Output is correct |
3 |
Correct |
172 ms |
54388 KB |
Output is correct |
4 |
Correct |
157 ms |
52160 KB |
Output is correct |
5 |
Correct |
168 ms |
53460 KB |
Output is correct |
6 |
Correct |
164 ms |
52412 KB |
Output is correct |
7 |
Correct |
164 ms |
53364 KB |
Output is correct |
8 |
Correct |
181 ms |
52204 KB |
Output is correct |
9 |
Correct |
150 ms |
52084 KB |
Output is correct |
10 |
Correct |
163 ms |
54384 KB |
Output is correct |
11 |
Correct |
161 ms |
52848 KB |
Output is correct |
12 |
Correct |
166 ms |
53876 KB |
Output is correct |
13 |
Correct |
178 ms |
52256 KB |
Output is correct |
14 |
Correct |
172 ms |
54144 KB |
Output is correct |
15 |
Correct |
163 ms |
53876 KB |
Output is correct |
16 |
Correct |
160 ms |
51760 KB |
Output is correct |
17 |
Correct |
182 ms |
53352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
197 ms |
52332 KB |
Output is correct |
2 |
Correct |
174 ms |
54256 KB |
Output is correct |
3 |
Correct |
172 ms |
54388 KB |
Output is correct |
4 |
Correct |
157 ms |
52160 KB |
Output is correct |
5 |
Correct |
168 ms |
53460 KB |
Output is correct |
6 |
Correct |
164 ms |
52412 KB |
Output is correct |
7 |
Correct |
164 ms |
53364 KB |
Output is correct |
8 |
Correct |
181 ms |
52204 KB |
Output is correct |
9 |
Correct |
150 ms |
52084 KB |
Output is correct |
10 |
Correct |
163 ms |
54384 KB |
Output is correct |
11 |
Correct |
161 ms |
52848 KB |
Output is correct |
12 |
Correct |
166 ms |
53876 KB |
Output is correct |
13 |
Correct |
178 ms |
52256 KB |
Output is correct |
14 |
Correct |
172 ms |
54144 KB |
Output is correct |
15 |
Correct |
163 ms |
53876 KB |
Output is correct |
16 |
Correct |
160 ms |
51760 KB |
Output is correct |
17 |
Correct |
182 ms |
53352 KB |
Output is correct |
18 |
Correct |
216 ms |
52592 KB |
Output is correct |
19 |
Correct |
290 ms |
54132 KB |
Output is correct |
20 |
Correct |
170 ms |
54132 KB |
Output is correct |
21 |
Correct |
185 ms |
52336 KB |
Output is correct |
22 |
Correct |
196 ms |
52588 KB |
Output is correct |
23 |
Correct |
171 ms |
52380 KB |
Output is correct |
24 |
Correct |
212 ms |
52852 KB |
Output is correct |
25 |
Correct |
165 ms |
52084 KB |
Output is correct |
26 |
Correct |
217 ms |
52080 KB |
Output is correct |
27 |
Correct |
244 ms |
54704 KB |
Output is correct |
28 |
Correct |
190 ms |
52580 KB |
Output is correct |
29 |
Correct |
195 ms |
53876 KB |
Output is correct |
30 |
Correct |
193 ms |
52016 KB |
Output is correct |
31 |
Correct |
198 ms |
53944 KB |
Output is correct |
32 |
Correct |
155 ms |
53920 KB |
Output is correct |
33 |
Correct |
210 ms |
51604 KB |
Output is correct |
34 |
Correct |
187 ms |
53360 KB |
Output is correct |