제출 #1331561

#제출 시각아이디문제언어결과실행 시간메모리
1331561nguyenkhangninh99Measures (CEOI22_measures)C++17
100 / 100
186 ms70944 KiB
//2t >= (j − i) * D − (x[j] - x[i]) 
//2t >= (d * j - x[j]) - (d * i - x[i])
//2t = max v[j] - v[i].
//maintain mx vj - vi segment tree
#include<bits/stdc++.h>
using namespace std;

#define int long long 
const int maxn = 5e5 + 5;
struct node{
    int mn, mx, cnt, res;
} st[4 * maxn];
int n, m, d;
node merge(node l, node r){
    return {min(l.mn, r.mn + l.cnt * d), max(l.mx, r.mx + l.cnt * d), l.cnt + r.cnt, max({l.res, r.res, (r.mx + l.cnt * d) - l.mn})};
}
void update(int id, int l, int r, int p, int val){
    if(l == r) st[id].mn = d - val, st[id].mx = d - val, st[id].cnt = 1;
    else{
        int mid = (l + r) / 2;
        if(p <= mid) update(id * 2, l, mid, p, val);
        else update(id * 2 + 1, mid + 1, r, p, val);
        st[id] = merge(st[id * 2], st[id * 2 + 1]);
    }
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    cin >> n >> m >> d;
   
    vector<int> order(n + m + 1), a(n + m + 1), pos(n + m + 1);
    for(int i = 1; i <= n + m; i++) cin >> a[i];
    for(int i = 1; i <= n + m; i++) order[i] = i;

    sort(order.begin() + 1, order.end(), [&](int x, int y){
        return a[x] < a[y] || (a[x] == a[y] && x < y);
    });
    for(int i = 1; i <= n + m; i++) pos[order[i]] = i;
    for(int i = 1; i < 4 * maxn; i++) st[i] = {(int)1e18, (int)-1e18, 0, 0}; 
    for(int i = 1; i <= n + m; i++){
        update(1, 1, n + m, pos[i], a[i]);
        if(i > n){
            cout << st[1].res / 2;
            if(st[1].res % 2 == 1) cout << ".5";
            cout << " ";

        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...