/**
* author: NimaAryan
* created: 2024-01-22 14:08:43
**/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "algo/debug.h"
#endif
using i64 = long long;
template <class Info, class Tag>
class LazySegmentTree {
public:
vector<Info> info;
vector<Tag> tag;
int n;
LazySegmentTree(int n) : n(n) {
info.assign(4 << __lg(n), Info());
tag.assign(4 << __lg(n), Tag());
}
void pull(int p) {
info[p] = info[2 * p] + info[2 * p + 1];
}
void apply(int p, const Tag& v) {
info[p].apply(v);
tag[p].apply(v);
}
void push(int p) {
apply(2 * p, tag[p]);
apply(2 * p + 1, tag[p]);
tag[p] = Tag();
}
void modify(int p, int l, int r, int x, const Info& v) {
if (r - l == 1) {
info[p] = v;
return;
}
int m = (l + r) / 2;
push(p);
if (x < m) {
modify(2 * p, l, m, x, v);
} else {
modify(2 * p + 1, m, r, x, v);
}
pull(p);
}
void modify(int p, const Info& v) {
modify(1, 0, n, p, v);
}
Info range_query(int p, int l, int r, int lx, int rx) {
if (l >= rx || r <= lx) {
return Info();
}
if (l >= lx && r <= rx) {
return info[p];
}
int m = (l + r) / 2;
push(p);
return range_query(2 * p, l, m, lx, rx) +
range_query(2 * p + 1, m, r, lx, rx);
}
Info range_query(int lx, int rx) {
return range_query(1, 0, n, lx, rx);
}
void range_apply(int p, int l, int r, int lx, int rx,
const Tag& v) {
if (l >= rx || r <= lx) {
return;
}
if (l >= lx && r <= rx) {
apply(p, v);
return;
}
int m = (l + r) / 2;
push(p);
range_apply(2 * p, l, m, lx, rx, v);
range_apply(2 * p + 1, m, r, lx, rx, v);
pull(p);
}
void range_apply(int lx, int rx, const Tag& v) {
range_apply(1, 0, n, lx, rx, v);
}
};
struct Tag {
i64 add = 0;
void apply(Tag t) {
add += t.add;
}
};
constexpr i64 inf = 1E16;
struct Info {
i64 min_value = +inf, max_value = -inf;
void apply(Tag t) {
if (min_value != +inf) {
min_value += t.add;
}
if (max_value != -inf) {
max_value += t.add;
}
}
};
Info operator+(Info a, Info b) {
return {min(a.min_value, b.min_value), max(a.max_value, b.max_value)};
}
template <typename T>
class Fenwick {
public:
int n;
vector<T> a;
Fenwick(int n) : n(n) {
a.assign(n, T{});
}
void add(int x, T v) {
for (int i = x + 1; i <= n; i += i & -i) {
a[i - 1] += v;
}
}
T sum(int x) {
T res{};
for (int i = x; i > 0; i -= i & -i) {
res += a[i - 1];
}
return res;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, D;
cin >> n >> m >> D;
vector<int> a(n + m);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = n; i < n + m; ++i) {
cin >> a[i];
}
vector<int> p(n + m);
iota(p.begin(), p.end(), 0);
sort(p.begin(), p.end(), [&](int i, int j) {
return a[i] < a[j];
});
vector<int> order(n + m);
for (int i = 0; i < n + m; ++i) {
order[p[i]] = i;
}
i64 t = 0;
LazySegmentTree<Info, Tag> seg(n + m);
Fenwick<int> fen(n + m);
auto add = [&](int x) {
i64 val = a[x] - 1LL * fen.sum(order[x]) * D;
seg.range_apply(order[x] + 1, n + m, {-D});
i64 left = seg.range_query(0, order[x]).max_value;
i64 right = seg.range_query(order[x] + 1, n + m).min_value;
t = max({t, left - val, val - right, left - right});
seg.modify(order[x], {val, val});
fen.add(order[x], +1);
};
for (int i = 0; i < n; ++i) {
add(i);
}
for (int i = n; i < n + m; ++i) {
add(i);
if (t % 2 == 0) {
cout << t / 2 << " \n"[i + 1 == n + m];
} else {
cout << t / 2 << ".5" << " \n"[i + 1 == n + m];
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
608 KB |
Output is correct |
7 |
Correct |
2 ms |
500 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
608 KB |
Output is correct |
7 |
Correct |
2 ms |
500 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
242 ms |
17840 KB |
Output is correct |
10 |
Correct |
246 ms |
17840 KB |
Output is correct |
11 |
Correct |
183 ms |
17868 KB |
Output is correct |
12 |
Correct |
208 ms |
17840 KB |
Output is correct |
13 |
Correct |
168 ms |
17384 KB |
Output is correct |
14 |
Correct |
178 ms |
17820 KB |
Output is correct |
15 |
Correct |
255 ms |
17168 KB |
Output is correct |
16 |
Correct |
169 ms |
17840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
186 ms |
18876 KB |
Output is correct |
2 |
Correct |
199 ms |
20740 KB |
Output is correct |
3 |
Correct |
222 ms |
20700 KB |
Output is correct |
4 |
Correct |
183 ms |
18436 KB |
Output is correct |
5 |
Correct |
192 ms |
19760 KB |
Output is correct |
6 |
Correct |
185 ms |
19096 KB |
Output is correct |
7 |
Correct |
202 ms |
20060 KB |
Output is correct |
8 |
Correct |
186 ms |
18628 KB |
Output is correct |
9 |
Correct |
186 ms |
18452 KB |
Output is correct |
10 |
Correct |
190 ms |
20792 KB |
Output is correct |
11 |
Correct |
189 ms |
19284 KB |
Output is correct |
12 |
Correct |
197 ms |
20296 KB |
Output is correct |
13 |
Correct |
185 ms |
18456 KB |
Output is correct |
14 |
Correct |
188 ms |
20392 KB |
Output is correct |
15 |
Correct |
194 ms |
20252 KB |
Output is correct |
16 |
Correct |
206 ms |
18056 KB |
Output is correct |
17 |
Correct |
188 ms |
19828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
186 ms |
18876 KB |
Output is correct |
2 |
Correct |
199 ms |
20740 KB |
Output is correct |
3 |
Correct |
222 ms |
20700 KB |
Output is correct |
4 |
Correct |
183 ms |
18436 KB |
Output is correct |
5 |
Correct |
192 ms |
19760 KB |
Output is correct |
6 |
Correct |
185 ms |
19096 KB |
Output is correct |
7 |
Correct |
202 ms |
20060 KB |
Output is correct |
8 |
Correct |
186 ms |
18628 KB |
Output is correct |
9 |
Correct |
186 ms |
18452 KB |
Output is correct |
10 |
Correct |
190 ms |
20792 KB |
Output is correct |
11 |
Correct |
189 ms |
19284 KB |
Output is correct |
12 |
Correct |
197 ms |
20296 KB |
Output is correct |
13 |
Correct |
185 ms |
18456 KB |
Output is correct |
14 |
Correct |
188 ms |
20392 KB |
Output is correct |
15 |
Correct |
194 ms |
20252 KB |
Output is correct |
16 |
Correct |
206 ms |
18056 KB |
Output is correct |
17 |
Correct |
188 ms |
19828 KB |
Output is correct |
18 |
Correct |
257 ms |
19016 KB |
Output is correct |
19 |
Correct |
262 ms |
20564 KB |
Output is correct |
20 |
Correct |
200 ms |
20596 KB |
Output is correct |
21 |
Correct |
225 ms |
18604 KB |
Output is correct |
22 |
Correct |
236 ms |
19080 KB |
Output is correct |
23 |
Correct |
199 ms |
18776 KB |
Output is correct |
24 |
Correct |
285 ms |
19392 KB |
Output is correct |
25 |
Correct |
188 ms |
18552 KB |
Output is correct |
26 |
Correct |
246 ms |
18560 KB |
Output is correct |
27 |
Correct |
284 ms |
20944 KB |
Output is correct |
28 |
Correct |
212 ms |
18988 KB |
Output is correct |
29 |
Correct |
247 ms |
20564 KB |
Output is correct |
30 |
Correct |
225 ms |
18540 KB |
Output is correct |
31 |
Correct |
227 ms |
20356 KB |
Output is correct |
32 |
Correct |
202 ms |
20308 KB |
Output is correct |
33 |
Correct |
298 ms |
18156 KB |
Output is correct |
34 |
Correct |
229 ms |
20044 KB |
Output is correct |