1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| #include <set> #include <map> #include <cstdio> #include <algorithm>
using namespace std;
const auto U = [](auto x) { return [x](auto ...y) { return x(x, y...); }; };
class maxplus3 { public: long long a, b, c, d, e, f, g, h, i; friend maxplus3 operator*(const maxplus3 &x, const maxplus3 &y) { return { max({x.a + y.a, x.b + y.d, x.c + y.g, -0x3f3f3f3f3f3f3f3fll}), max({x.a + y.b, x.b + y.e, x.c + y.h, -0x3f3f3f3f3f3f3f3fll}), max({x.a + y.c, x.b + y.f, x.c + y.i, -0x3f3f3f3f3f3f3f3fll}), max({x.d + y.a, x.e + y.d, x.f + y.g, -0x3f3f3f3f3f3f3f3fll}), max({x.d + y.b, x.e + y.e, x.f + y.h, -0x3f3f3f3f3f3f3f3fll}), max({x.d + y.c, x.e + y.f, x.f + y.i, -0x3f3f3f3f3f3f3f3fll}), max({x.g + y.a, x.h + y.d, x.i + y.g, -0x3f3f3f3f3f3f3f3fll}), max({x.g + y.b, x.h + y.e, x.i + y.h, -0x3f3f3f3f3f3f3f3fll}), max({x.g + y.c, x.h + y.f, x.i + y.i, -0x3f3f3f3f3f3f3f3fll}), }; } };
class segtree { public: maxplus3 vals[400035]; constexpr int getr(int l, int r, int id) { return id + ((l + r) / 2 - l + 1) * 2; } void pushup(int l, int r, int id) { vals[id] = vals[getr(l, r, id)] * vals[id + 1]; } void build(int n) { U([&](auto &&self, int l, int r, int id) -> void { if(l == r) { vals[id] = {0, -0x3f3f3f3f3f3f3f3fll, -0x3f3f3f3f3f3f3f3fll, -0x3f3f3f3f3f3f3f3fll, 0, -0x3f3f3f3f3f3f3f3fll, -0x3f3f3f3f3f3f3f3fll, -0x3f3f3f3f3f3f3f3fll, 0}; return; } self(self, l, (l + r) / 2, id + 1); self(self, (l + r) / 2 + 1, r, getr(l, r, id)); pushup(l, r, id); })(1, n, 1); } void vmul(int n, int pos, const maxplus3 &val) { U([&](auto &&self, int l, int r, int id) -> void { if(l == r) { vals[id] = vals[id] * val; return; } if(pos <= (l + r) / 2) self(self, l, (l + r) / 2, id + 1); else self(self, (l + r) / 2 + 1, r, getr(l, r, id)); pushup(l, r, id); })(1, n, 1); } long long query() { return max(vals[1].e, vals[1].f); } } sg;
int a[200005], b[200005]; int yx[400005];
int main() { int n, m, d; scanf("%d%d%d", &n, &m, &d); map<int, int> mp; for(int i=1;i<=n;i++) { scanf("%d", a + i); mp[a[i]]; } for(int i=1;i<=m;i++) { scanf("%d", b + i); mp[b[i]]; } int cur = 0; for(auto &[x, y] : mp) yx[y = ++cur] = x; sg.build(cur); for(int i=1;i<=n;i++) { sg.vmul(cur, mp[a[i]], maxplus3{d, -0x3f3f3f3f3f3f3f3fll, a[i], d - a[i], 0, 0, -0x3f3f3f3f3f3f3f3fll, -0x3f3f3f3f3f3f3f3fll, 0}); } for(int i=1;i<=m;i++) { sg.vmul(cur, mp[b[i]], maxplus3{d, -0x3f3f3f3f3f3f3f3fll, b[i], d - b[i], 0, 0, -0x3f3f3f3f3f3f3f3fll, -0x3f3f3f3f3f3f3f3fll, 0}); long long res = sg.query(); if(res & 1) printf("%lld.5 ", res / 2); else printf("%lld ", res / 2); } return 0; }
|