답안 #969261

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
969261 2024-04-24T20:36:11 Z DAleksa Measures (CEOI22_measures) C++17
100 / 100
285 ms 41364 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

struct Fenwick {
    int n;
    vector<int> fw;
    Fenwick(int _n) {
        n = _n;
        fw.resize(n);
        for(int i = 0; i < n; i++) fw[i] = 0;
    }
    void update(int x) { for(int i = x; i < n; i += (i & -i)) fw[i]++; }
    int get(int r) {
        int ans = 0;
        for(int i = r; i >= 1; i -= (i & -i)) ans += fw[i];
        return ans;
    }
};

const long long inf = 1e18;

struct node {
    long long mx;
    long long mn;
    long long ans;
    long long lzy;
    node() {
        mx = -inf;
        mn = inf;
        ans = 0;
        lzy = 0;
    }
};

const int N = 2e5 + 20;
int n, m, D;
int a[N];
node st[4 * N];
vector<int> all;
int toa[N], tob[N];
int order[N];
int to[N];
int ind[N];
Fenwick fw(N);

node mrg(node L, node R) {
    node nd;
    nd.mx = max(L.mx, R.mx);
    nd.mn = min(L.mn, R.mn);
    nd.ans = max({L.ans, R.ans, L.mx - R.mn});
    nd.lzy = 0;
    return nd;
}

void propagate(int index) {
    if(2 * index + 1 < 4 * N) {
        st[2 * index].mx += st[index].lzy;
        st[2 * index].mn += st[index].lzy;
        st[2 * index].lzy += st[index].lzy;
        st[2 * index + 1].mx += st[index].lzy;
        st[2 * index + 1].mn += st[index].lzy;
        st[2 * index + 1].lzy += st[index].lzy;
        st[index].lzy = 0;
    }
}

void update(int index, int l, int r, int L, int R, int val) {
    if(l > r || r < L || R < l) return;
    if(L <= l && r <= R) {
        st[index].mx += val;
        st[index].mn += val;
        st[index].lzy += val;
        return;
    }
    int mid = (l + r) / 2;
    propagate(index);
    update(2 * index, l, mid, L, R, val);
    update(2 * index + 1, mid + 1, r, L, R, val);
    st[index] = mrg(st[2 * index], st[2 * index + 1]);
}

void modify(int index, int l, int r, int x, int val) {
    if(l > r || r < x || x < l) return;
    if(l == r) {
        st[index].mx = st[index].mn = val;
        st[index].ans = 0;
        return;
    }
    int mid = (l + r) / 2;
    propagate(index);
    modify(2 * index, l, mid, x, val);
    modify(2 * index + 1, mid + 1, r, x, val);
    st[index] = mrg(st[2 * index], st[2 * index + 1]);
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m >> D;
    n += m;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        order[i] = i;
    }
    sort(order + 1, order + n + 1, [&](int i, int j) { return a[i] < a[j]; });
    for(int i = 1; i <= n; i++) to[order[i]] = i;
    for(int qind = 1; qind <= n; qind++) {
        fw.update(to[qind]);
        update(1, 1, n, to[qind] + 1, n, -D);
        modify(1, 1, n, to[qind], a[qind] - D * 1LL * fw.get(to[qind] - 1));
        if(qind <= n - m) continue;
//        cout << fw.get(to[qind] - 1) << " ";
//        cout << st[1].mx << " " << st[1].mn << "\n";
        cout << st[1].ans / 2 << (st[1].ans % 2 == 1 ? ".5 " : " ");
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 32600 KB Output is correct
2 Correct 7 ms 32604 KB Output is correct
3 Correct 6 ms 32600 KB Output is correct
4 Correct 7 ms 32604 KB Output is correct
5 Correct 7 ms 32604 KB Output is correct
6 Correct 7 ms 32604 KB Output is correct
7 Correct 8 ms 32860 KB Output is correct
8 Correct 7 ms 32604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 32600 KB Output is correct
2 Correct 7 ms 32604 KB Output is correct
3 Correct 6 ms 32600 KB Output is correct
4 Correct 7 ms 32604 KB Output is correct
5 Correct 7 ms 32604 KB Output is correct
6 Correct 7 ms 32604 KB Output is correct
7 Correct 8 ms 32860 KB Output is correct
8 Correct 7 ms 32604 KB Output is correct
9 Correct 238 ms 38208 KB Output is correct
10 Correct 223 ms 37972 KB Output is correct
11 Correct 172 ms 38224 KB Output is correct
12 Correct 194 ms 37972 KB Output is correct
13 Correct 166 ms 37720 KB Output is correct
14 Correct 184 ms 38224 KB Output is correct
15 Correct 226 ms 37456 KB Output is correct
16 Correct 168 ms 37972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 183 ms 37312 KB Output is correct
2 Correct 184 ms 39252 KB Output is correct
3 Correct 190 ms 41300 KB Output is correct
4 Correct 180 ms 38796 KB Output is correct
5 Correct 186 ms 40112 KB Output is correct
6 Correct 182 ms 39248 KB Output is correct
7 Correct 181 ms 40104 KB Output is correct
8 Correct 181 ms 38992 KB Output is correct
9 Correct 181 ms 38740 KB Output is correct
10 Correct 188 ms 41364 KB Output is correct
11 Correct 182 ms 39780 KB Output is correct
12 Correct 185 ms 40788 KB Output is correct
13 Correct 180 ms 38992 KB Output is correct
14 Correct 187 ms 41016 KB Output is correct
15 Correct 184 ms 40788 KB Output is correct
16 Correct 181 ms 38408 KB Output is correct
17 Correct 185 ms 40276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 183 ms 37312 KB Output is correct
2 Correct 184 ms 39252 KB Output is correct
3 Correct 190 ms 41300 KB Output is correct
4 Correct 180 ms 38796 KB Output is correct
5 Correct 186 ms 40112 KB Output is correct
6 Correct 182 ms 39248 KB Output is correct
7 Correct 181 ms 40104 KB Output is correct
8 Correct 181 ms 38992 KB Output is correct
9 Correct 181 ms 38740 KB Output is correct
10 Correct 188 ms 41364 KB Output is correct
11 Correct 182 ms 39780 KB Output is correct
12 Correct 185 ms 40788 KB Output is correct
13 Correct 180 ms 38992 KB Output is correct
14 Correct 187 ms 41016 KB Output is correct
15 Correct 184 ms 40788 KB Output is correct
16 Correct 181 ms 38408 KB Output is correct
17 Correct 185 ms 40276 KB Output is correct
18 Correct 249 ms 39332 KB Output is correct
19 Correct 263 ms 41300 KB Output is correct
20 Correct 189 ms 41044 KB Output is correct
21 Correct 208 ms 39112 KB Output is correct
22 Correct 220 ms 39252 KB Output is correct
23 Correct 195 ms 39112 KB Output is correct
24 Correct 270 ms 39924 KB Output is correct
25 Correct 179 ms 38808 KB Output is correct
26 Correct 285 ms 38856 KB Output is correct
27 Correct 240 ms 41280 KB Output is correct
28 Correct 222 ms 39356 KB Output is correct
29 Correct 237 ms 40532 KB Output is correct
30 Correct 209 ms 38820 KB Output is correct
31 Correct 214 ms 40984 KB Output is correct
32 Correct 193 ms 40528 KB Output is correct
33 Correct 234 ms 38356 KB Output is correct
34 Correct 210 ms 40280 KB Output is correct