Submission #1044165

# Submission time Handle Problem Language Result Execution time Memory
1044165 2024-08-05T07:44:23 Z 변재우(#11009) Measures (CEOI22_measures) C++17
24 / 100
1500 ms 36412 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int Nmax=200010, INF=1e18;
int N, M, D, A[Nmax], B[Nmax], X[Nmax];
vector<int> V;
multiset<pair<int, int>> S;
map<int, int> cnt;

void Add(int x) {
    int i=lower_bound(V.begin(), V.end(), x)-V.begin()+1+cnt[x];
    cnt[x]++;
    auto p=S.upper_bound(make_pair(x, INF));
    if(S.empty()) {
        S.insert({x, i});
        return;
    }
    if(p==S.end()) {
        p=prev(p);
        X[i]=D-(x-(*p).first);
    }
    else if(p==S.begin()) {
        X[(*p).second]=D-((*p).first-x);
    }
    else {
        X[(*p).second]=D-((*p).first-x);
        p=prev(p);
        X[i]=D-(x-(*p).first);
    }
    S.insert({x, i});
}

int Query() {
    int ret=-INF;
    int Y[Nmax]={0}, R[Nmax]={0}, L[Nmax]={0};
    for(int i=1; i<=N+M; i++) Y[i]=Y[i-1]+X[i];
    R[N+M]=Y[N+M], L[1]=Y[1];
    for(int i=2; i<=N+M; i++) L[i]=min(L[i-1], Y[i]);
    for(int i=N+M-1; i>=1; i--) R[i]=max(R[i+1], Y[i]);
    for(int i=0; i<N+M; i++) ret=max(ret, R[i+1]-L[i]);
    return max(0ll, ret);
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>N>>M>>D;
    for(int i=1; i<=N; i++) cin>>A[i], V.push_back(A[i]);
    for(int i=1; i<=M; i++) cin>>B[i], V.push_back(B[i]);
    sort(V.begin(), V.end());
    for(int i=1; i<=N; i++) Add(A[i]);
    for(int i=1; i<=M; i++) {
        Add(B[i]);
        int tmp=Query();
        if(tmp%2) cout<<tmp/2<<".5 ";
        else cout<<tmp/2<<" ";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9544 KB Output is correct
2 Correct 6 ms 9308 KB Output is correct
3 Correct 4 ms 9308 KB Output is correct
4 Correct 6 ms 9308 KB Output is correct
5 Correct 6 ms 9332 KB Output is correct
6 Correct 5 ms 9308 KB Output is correct
7 Correct 5 ms 9420 KB Output is correct
8 Correct 4 ms 9308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9544 KB Output is correct
2 Correct 6 ms 9308 KB Output is correct
3 Correct 4 ms 9308 KB Output is correct
4 Correct 6 ms 9308 KB Output is correct
5 Correct 6 ms 9332 KB Output is correct
6 Correct 5 ms 9308 KB Output is correct
7 Correct 5 ms 9420 KB Output is correct
8 Correct 4 ms 9308 KB Output is correct
9 Correct 250 ms 36364 KB Output is correct
10 Correct 257 ms 36316 KB Output is correct
11 Correct 80 ms 23696 KB Output is correct
12 Correct 148 ms 36364 KB Output is correct
13 Correct 131 ms 36336 KB Output is correct
14 Correct 143 ms 36248 KB Output is correct
15 Correct 248 ms 36412 KB Output is correct
16 Correct 114 ms 36256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1542 ms 11012 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1542 ms 11012 KB Time limit exceeded
2 Halted 0 ms 0 KB -