답안 #969260

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

using namespace std;

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]);
}

int 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 12 ms 30044 KB Output is correct
2 Correct 6 ms 30044 KB Output is correct
3 Correct 7 ms 30044 KB Output is correct
4 Correct 8 ms 30044 KB Output is correct
5 Correct 8 ms 30040 KB Output is correct
6 Correct 6 ms 30044 KB Output is correct
7 Correct 7 ms 30044 KB Output is correct
8 Incorrect 6 ms 30044 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 30044 KB Output is correct
2 Correct 6 ms 30044 KB Output is correct
3 Correct 7 ms 30044 KB Output is correct
4 Correct 8 ms 30044 KB Output is correct
5 Correct 8 ms 30040 KB Output is correct
6 Correct 6 ms 30044 KB Output is correct
7 Correct 7 ms 30044 KB Output is correct
8 Incorrect 6 ms 30044 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 184 ms 33676 KB Output is correct
2 Incorrect 190 ms 34948 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 184 ms 33676 KB Output is correct
2 Incorrect 190 ms 34948 KB Output isn't correct
3 Halted 0 ms 0 KB -