제출 #1331524

#제출 시각아이디문제언어결과실행 시간메모리
1331524nguyenkhangninh99Measures (CEOI22_measures)C++17
35 / 100
150 ms69312 KiB

#include<bits/stdc++.h>
using namespace std;

#define int long long 
const int maxn = 5e5 + 5;
struct node{
    int a, b, cnt, mx;
} st[4 * maxn];
int n, m, d;
node merge(node l, node r){
    return {min(l.a, r.a + l.cnt * d), max(l.b, r.b + l.cnt * d), l.cnt + r.cnt, max({l.mx, r.mx, r.b + l.cnt * d - l.a})};
}
void update(int id, int l, int r, int p, int val){
    if(l == r) st[id].a = d - val, st[id].b = 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]);
    }
}
void solve(){
    cin >> n >> m >> d;
   
    vector<int> order(n + m + 1), a(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 < 4 * maxn; i++) st[i].a = 1e18, st[i].mx = 0, st[i].b = -1e18, st[i].cnt = 0;
    for(int i = 1; i <= n + m; i++){
        update(1, 1, n + m, order[i], a[i]);
        if(i > n){
            cout << st[1].mx / 2;
            if(st[1].mx % 2 == 1) cout << ".5";
            cout << " ";

        }
    }
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...