Submission #657202

# Submission time Handle Problem Language Result Execution time Memory
657202 2022-11-09T06:21:47 Z dooompy Measures (CEOI22_measures) C++17
100 / 100
182 ms 42728 KB
#include "bits/stdc++.h"

using namespace std;

void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
    cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
    while (l != r) cout << *l << " \n"[++l == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
    return o >> a.first >> a.second;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
    return o << '(' << a.first << ", " << a.second << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
    bool is = false;
    for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
    return o << '}';
}

#ifdef local
#define test(args...) abc("[" + string(#args) + "]", args)
#else
#define test(args...) void(0)
#endif

using ll = long long;

#define int ll

ll pos[400000];
ll val[400000];

struct node {
    ll mn, mx, lz, ans;
};

node tree[400000 * 4];

void sett(int x, int l, int r, int p, int v) {
    if (l == r) {
        tree[x].mn = tree[x].mx = v + tree[x].lz;
        tree[x].ans = 0;
        return;
    }

    int mid = (l + r) / 2;

    if (p <= mid) sett(2 * x, l, mid, p, v);
    else sett(2 * x + 1, mid + 1, r, p, v);

    tree[x].mn = tree[x].lz + min(tree[2 * x].mn, tree[2 * x + 1].mn);
    tree[x].mx = tree[x].lz + max(tree[2 * x].mx, tree[2 * x + 1].mx);
    tree[x].ans = max({tree[2 * x].ans, tree[2 * x + 1].ans, tree[2 * x].mx - tree[2 * x + 1].mn});
}

void add(int x, int l, int r, int ql, int qr, int v) {
    if (ql <= l && r <= qr) {
        tree[x].lz += v;
        tree[x].mx += v;
        tree[x].mn += v;
        return;
    }

    if (l > qr || ql > r) return;

    int mid = (l + r) / 2;

    add(2 * x, l, mid, ql, qr, v);
    add(2 * x + 1, mid + 1, r, ql, qr, v);

    tree[x].mn = tree[x].lz + min(tree[2 * x].mn, tree[2 * x + 1].mn);
    tree[x].mx = tree[x].lz + max(tree[2 * x].mx, tree[2 * x + 1].mx);
    tree[x].ans = max({tree[2 * x].ans, tree[2 * x + 1].ans, tree[2 * x].mx - tree[2 * x + 1].mn});
}

void build(int x, int l, int r) {
    tree[x].mn = 1e15;
    tree[x].mx = -1e15;
    tree[x].ans = -1e15;


    if (l == r) {
        return;
    }

    int mid = (l + r) / 2;

    build(2 * x, l, mid);
    build(2 * x + 1, mid + 1, r);
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);
    int n, m, d; cin >> n >> m >> d;

    build(1, 1, 400000);
    vector<pair<ll, ll>> v;
    for (int i = 1; i <= n + m; i++) {
        int t; cin >> t;
        val[i] = t;
        v.push_back({t, i});
    }

    sort(v.begin(), v.end());

    for (int i = 1; i <= n + m; i++) {
        pos[v[i - 1].second] = i;
    }

    for (int i = 1; i <= n; i++) {
        sett(1, 1, 400000, pos[i], val[i]);
        add(1, 1, 400000, pos[i] + 1, 400000, -d);
    }

    for (int i = n + 1; i <= n + m; i++) {
        sett(1, 1, 400000, pos[i], val[i]);
        add(1, 1, 400000, pos[i] + 1, 400000, -d);

        ll res = tree[1].ans;

        if (res % 2 == 1) {
            cout << res / 2  <<  ".5 ";
        } else cout << res / 2 << " " ;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 15 ms 33236 KB Output is correct
2 Correct 15 ms 33204 KB Output is correct
3 Correct 16 ms 33236 KB Output is correct
4 Correct 16 ms 33224 KB Output is correct
5 Correct 16 ms 33244 KB Output is correct
6 Correct 16 ms 33236 KB Output is correct
7 Correct 15 ms 33272 KB Output is correct
8 Correct 18 ms 33216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 33236 KB Output is correct
2 Correct 15 ms 33204 KB Output is correct
3 Correct 16 ms 33236 KB Output is correct
4 Correct 16 ms 33224 KB Output is correct
5 Correct 16 ms 33244 KB Output is correct
6 Correct 16 ms 33236 KB Output is correct
7 Correct 15 ms 33272 KB Output is correct
8 Correct 18 ms 33216 KB Output is correct
9 Correct 178 ms 39536 KB Output is correct
10 Correct 158 ms 41196 KB Output is correct
11 Correct 115 ms 40512 KB Output is correct
12 Correct 146 ms 40756 KB Output is correct
13 Correct 104 ms 40396 KB Output is correct
14 Correct 115 ms 40440 KB Output is correct
15 Correct 162 ms 40396 KB Output is correct
16 Correct 132 ms 40336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 128 ms 40560 KB Output is correct
2 Correct 134 ms 42436 KB Output is correct
3 Correct 133 ms 42400 KB Output is correct
4 Correct 138 ms 40272 KB Output is correct
5 Correct 129 ms 41556 KB Output is correct
6 Correct 120 ms 40700 KB Output is correct
7 Correct 126 ms 41660 KB Output is correct
8 Correct 139 ms 40320 KB Output is correct
9 Correct 125 ms 40288 KB Output is correct
10 Correct 130 ms 42660 KB Output is correct
11 Correct 126 ms 41056 KB Output is correct
12 Correct 139 ms 42088 KB Output is correct
13 Correct 126 ms 40280 KB Output is correct
14 Correct 139 ms 42204 KB Output is correct
15 Correct 133 ms 42044 KB Output is correct
16 Correct 119 ms 40376 KB Output is correct
17 Correct 129 ms 41552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 128 ms 40560 KB Output is correct
2 Correct 134 ms 42436 KB Output is correct
3 Correct 133 ms 42400 KB Output is correct
4 Correct 138 ms 40272 KB Output is correct
5 Correct 129 ms 41556 KB Output is correct
6 Correct 120 ms 40700 KB Output is correct
7 Correct 126 ms 41660 KB Output is correct
8 Correct 139 ms 40320 KB Output is correct
9 Correct 125 ms 40288 KB Output is correct
10 Correct 130 ms 42660 KB Output is correct
11 Correct 126 ms 41056 KB Output is correct
12 Correct 139 ms 42088 KB Output is correct
13 Correct 126 ms 40280 KB Output is correct
14 Correct 139 ms 42204 KB Output is correct
15 Correct 133 ms 42044 KB Output is correct
16 Correct 119 ms 40376 KB Output is correct
17 Correct 129 ms 41552 KB Output is correct
18 Correct 180 ms 40736 KB Output is correct
19 Correct 177 ms 42348 KB Output is correct
20 Correct 139 ms 42440 KB Output is correct
21 Correct 153 ms 40404 KB Output is correct
22 Correct 159 ms 40816 KB Output is correct
23 Correct 137 ms 40652 KB Output is correct
24 Correct 182 ms 41176 KB Output is correct
25 Correct 141 ms 40228 KB Output is correct
26 Correct 174 ms 40308 KB Output is correct
27 Correct 180 ms 42728 KB Output is correct
28 Correct 155 ms 40760 KB Output is correct
29 Correct 168 ms 42076 KB Output is correct
30 Correct 160 ms 40268 KB Output is correct
31 Correct 178 ms 42216 KB Output is correct
32 Correct 141 ms 42200 KB Output is correct
33 Correct 174 ms 40344 KB Output is correct
34 Correct 174 ms 41600 KB Output is correct