답안 #809238

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
809238 2023-08-05T23:16:03 Z HaroldVemeno Measures (CEOI22_measures) C++17
100 / 100
230 ms 16388 KB
#include <bits/stdc++.h>

#ifdef GUDEB
    #define D(x) cerr << #x << ": " << (x) << '\n';
    #define ifdeb if(true)
#else
    #define D(x) ;
    #define ifdeb if(false)
#endif

#define all(x) begin(x), end(x)

using namespace std;
using pii = pair<int, int>;
using ull = unsigned long long;
using ll = long long;
// #define int ll;

int n, m, d;

struct Node {
    int v;
    int p;
    int ss;
    ll lm;
    ll rm;
    ll time;
    Node* l;
    Node* r;
};

int size(Node* a) {
    return a?a->ss:0;
}

Node* pull(Node* a) {
    if(!a) return a;
    int ls = size(a->l);
    int rs = size(a->r);
    D(a->v);
    a->ss = 1+ls+rs;
    a->time = 0;
    a->rm = a->v + 1ll*d*rs;
    a->lm = a->v - 1ll*d*ls;
    ll mv = a->v + d*size(a->l);
    if(a->r) {
        a->time = max(a->time, a->r->time);
        a->time = max(a->time, d-(a->r->lm - a->v));
        a->rm = max(a->rm, a->r->rm);
        a->lm = min(a->lm, a->r->lm - (ls+1ll)*d);
    }
    if(a->l) {
        a->time = max(a->time, a->l->time);
        a->time = max(a->time, d-(a->v - a->l->rm));
        a->lm = min(a->lm, a->l->lm);
        a->rm = max(a->rm, a->l->rm + (rs+1ll)*d);
    }
    if(a->l && a->r) {
        a->time = max(a->time, 2*d-(a->r->lm - a->l->rm));
    }
    return a;
}

Node* concat(Node* l, Node* r) {
    if(!l) return r;
    if(!r) return l;
    if(l->p > r->p) {
        l->r = concat(l->r, r);
        pull(l);
        return l;
    } else {
        r->l = concat(l, r->l);
        pull(r);
        return r;
    }
}

pair<Node*, Node*> split(Node* a, ll v) {
    if(!a) return {a, a};
    if(a->v < v) {
        auto[l, r] = split(a->r, v);
        a->r = l;
        pull(a);
        return {a, r};
    } else {
        auto[l, r] = split(a->l, v);
        a->l = r;
        pull(a);
        return {l, a};
    }
}

void solve() {
    cin >> n >> m >> d;
    srand(48364);
    vector<Node> buf(n+m);
    for(int i = 0; i < n; ++i) {
        cin >> buf[i].v;
        buf[i].p = rand();
        pull(&buf[i]);
    }
    for(int i = 0; i < m; ++i) {
        cin >> buf[n+i].v;
        buf[n+i].p = rand();
        pull(&buf[n+i]);
    }

    Node* tr = nullptr;
    for(int i = 0; i < n; ++i) {
        auto [l, r] = split(tr, buf[i].v);
        tr = concat(l, concat(&buf[i], r));
        D(tr->ss);
    }
    for(int i = n;  i < n+m; ++i) {
        auto [l, r] = split(tr, buf[i].v);
        tr = concat(l, concat(&buf[i], r));
        D(tr->ss);
        D(tr->rm);
        D(tr->lm);
        cout << tr->time/2;
        if(tr->time&1) cout << ".5";
        cout << ' ';
    }
    cout << '\n';

    return;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed;

    solve();
}

Compilation message

Main.cpp: In function 'Node* pull(Node*)':
Main.cpp:45:8: warning: unused variable 'mv' [-Wunused-variable]
   45 |     ll mv = a->v + d*size(a->l);
      |        ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 219 ms 11220 KB Output is correct
10 Correct 197 ms 11220 KB Output is correct
11 Correct 68 ms 11220 KB Output is correct
12 Correct 111 ms 11220 KB Output is correct
13 Correct 69 ms 11220 KB Output is correct
14 Correct 150 ms 11220 KB Output is correct
15 Correct 207 ms 11220 KB Output is correct
16 Correct 67 ms 11216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 12284 KB Output is correct
2 Correct 92 ms 14216 KB Output is correct
3 Correct 86 ms 14156 KB Output is correct
4 Correct 83 ms 12024 KB Output is correct
5 Correct 87 ms 13308 KB Output is correct
6 Correct 85 ms 12360 KB Output is correct
7 Correct 88 ms 13332 KB Output is correct
8 Correct 84 ms 12100 KB Output is correct
9 Correct 85 ms 11924 KB Output is correct
10 Correct 89 ms 14452 KB Output is correct
11 Correct 89 ms 12956 KB Output is correct
12 Correct 88 ms 13820 KB Output is correct
13 Correct 85 ms 11976 KB Output is correct
14 Correct 88 ms 13932 KB Output is correct
15 Correct 93 ms 13800 KB Output is correct
16 Correct 83 ms 12052 KB Output is correct
17 Correct 86 ms 13324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 12284 KB Output is correct
2 Correct 92 ms 14216 KB Output is correct
3 Correct 86 ms 14156 KB Output is correct
4 Correct 83 ms 12024 KB Output is correct
5 Correct 87 ms 13308 KB Output is correct
6 Correct 85 ms 12360 KB Output is correct
7 Correct 88 ms 13332 KB Output is correct
8 Correct 84 ms 12100 KB Output is correct
9 Correct 85 ms 11924 KB Output is correct
10 Correct 89 ms 14452 KB Output is correct
11 Correct 89 ms 12956 KB Output is correct
12 Correct 88 ms 13820 KB Output is correct
13 Correct 85 ms 11976 KB Output is correct
14 Correct 88 ms 13932 KB Output is correct
15 Correct 93 ms 13800 KB Output is correct
16 Correct 83 ms 12052 KB Output is correct
17 Correct 86 ms 13324 KB Output is correct
18 Correct 220 ms 12432 KB Output is correct
19 Correct 230 ms 16108 KB Output is correct
20 Correct 90 ms 16076 KB Output is correct
21 Correct 135 ms 14132 KB Output is correct
22 Correct 178 ms 14428 KB Output is correct
23 Correct 155 ms 14220 KB Output is correct
24 Correct 230 ms 14772 KB Output is correct
25 Correct 90 ms 13960 KB Output is correct
26 Correct 230 ms 13840 KB Output is correct
27 Correct 227 ms 16388 KB Output is correct
28 Correct 159 ms 14332 KB Output is correct
29 Correct 181 ms 15664 KB Output is correct
30 Correct 126 ms 13916 KB Output is correct
31 Correct 127 ms 15844 KB Output is correct
32 Correct 160 ms 15680 KB Output is correct
33 Correct 228 ms 13580 KB Output is correct
34 Correct 129 ms 15304 KB Output is correct