답안 #1091754

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1091754 2024-09-22T03:01:31 Z vjudge1 Measures (CEOI22_measures) C++14
100 / 100
282 ms 22492 KB
#include <bits/stdc++.h>
using namespace std;

#define TRACE(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define _ << " _ " <<

template<class> struct is_container : false_type {};
template<class... Ts> struct is_container<vector<Ts...>> : true_type {};
template<class... Ts> struct is_container<map<Ts...>> : true_type {};
template<class... Ts> struct is_container<unordered_map<Ts...>> : true_type {};
template<class... Ts> struct is_container<set<Ts...>> : true_type {};
template<class... Ts> struct is_container<unordered_set<Ts...>> : true_type {};
template<class... Ts> struct is_container<multiset<Ts...>> : true_type {};
template<class... Ts> struct is_container<unordered_multiset<Ts...>> : true_type {};
template<class T, class = typename enable_if<is_container<T>::value>::type>
ostream& operator<<(ostream &o, T x) {
  int f = 1;
  o << "{";
  for (auto y : x) {
    o << (f ? "" : ", ") << y;
    f = 0;
  }
  return o << "}";
}
template<class T, class U>
ostream& operator<<(ostream &o, pair<T, U> x) {
  return o << "(" << x.first << ", " << x.second << ")";
}

#define fi first
#define se second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const int OFF = 1 << 18;
const ll INF = 1e18;

struct SegTree {
    ll mini[2 * OFF], maxi[2 * OFF], lazy[2 * OFF];

    SegTree() {
        for (int i = 1; i < 2 * OFF; i++) {
            mini[i] = INF;
            maxi[i] = -INF;
        }
    }

    void propagate(int i) {
        mini[2 * i + 0] += lazy[i];
        maxi[2 * i + 0] += lazy[i];
        lazy[2 * i + 0] += lazy[i];
        mini[2 * i + 1] += lazy[i];
        maxi[2 * i + 1] += lazy[i];
        lazy[2 * i + 1] += lazy[i];
        lazy[i] = 0;
    }

    void update(int i) {
        mini[i] = min(mini[2 * i], mini[2 * i + 1]);
        maxi[i] = max(maxi[2 * i], maxi[2 * i + 1]);
    }

    void set(int pos, ll val, int i = 1, int lo = 0, int hi = OFF) {
        if (lo + 1 == hi) {
            mini[i] += val - INF;
            maxi[i] += val + INF;
        } else {
            propagate(i);
            int mid = (lo + hi) / 2;
            if (pos < mid) set(pos, val, 2 * i + 0, lo, mid);
            else set(pos, val, 2 * i + 1, mid, hi);
            update(i);
        }
    }

    void add(int l, int r, ll val, int i = 1, int lo = 0, int hi = OFF) {
        if (l <= lo && hi <= r) {
            mini[i] += val;
            maxi[i] += val;
            lazy[i] += val;
        } else if (r <= lo || hi <= l) return;
        else {
            propagate(i);
            int mid = (lo + hi) / 2;
            add(l, r, val, 2 * i + 0, lo, mid);
            add(l, r, val, 2 * i + 1, mid, hi);
            update(i);
        }
    }

    pll query(int l, int r, int i = 1, int lo = 0, int hi = OFF) {
        if (l <= lo && hi <= r) return {mini[i], maxi[i]};
        else if (r <= lo || hi <= l) return {INF, -INF};
        else {
            propagate(i);
            int mid = (lo + hi) / 2;
            auto p = query(l, r, 2 * i + 0, lo, mid);
            auto q = query(l, r, 2 * i + 1, mid, hi);
            return {min(p.fi, q.fi), max(p.se, q.se)};
        }
    }
} T;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    ll d;
    cin >> n >> m >> d;
    vll x(n + m);
    vector<pll> vec(n + m);
    for (int i = 0; i < n + m; i++) {
        cin >> x[i];
        vec[i] = {x[i], i};
    }
    sort(vec.begin(), vec.end());
    vi idx(n + m);
    for (int i = 0; i < n + m; i++) idx[vec[i].se] = i;

    ll sol = 0;
    for (int i = 0; i < n + m; i++) {
        T.set(idx[i], -x[i]);
        T.add(idx[i], OFF, d);

        sol = max(sol, T.query(idx[i], OFF).se - T.query(0, idx[i]).fi);
        sol = max(sol, T.query(idx[i] + 1, OFF).se - T.query(0, idx[i] + 1).fi);

        if (i >= n) cout << sol / 2 << ((sol & 1) ? ".5" : "") << " ";
    }
    cout << "\n";

    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8792 KB Output is correct
2 Correct 7 ms 8792 KB Output is correct
3 Correct 6 ms 8796 KB Output is correct
4 Correct 7 ms 8796 KB Output is correct
5 Correct 5 ms 8796 KB Output is correct
6 Correct 5 ms 8796 KB Output is correct
7 Correct 6 ms 8796 KB Output is correct
8 Correct 5 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8792 KB Output is correct
2 Correct 7 ms 8792 KB Output is correct
3 Correct 6 ms 8796 KB Output is correct
4 Correct 7 ms 8796 KB Output is correct
5 Correct 5 ms 8796 KB Output is correct
6 Correct 5 ms 8796 KB Output is correct
7 Correct 6 ms 8796 KB Output is correct
8 Correct 5 ms 8796 KB Output is correct
9 Correct 248 ms 19244 KB Output is correct
10 Correct 240 ms 19152 KB Output is correct
11 Correct 182 ms 19028 KB Output is correct
12 Correct 215 ms 19024 KB Output is correct
13 Correct 184 ms 18772 KB Output is correct
14 Correct 240 ms 19112 KB Output is correct
15 Correct 255 ms 18512 KB Output is correct
16 Correct 191 ms 19092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 222 ms 20176 KB Output is correct
2 Correct 203 ms 22096 KB Output is correct
3 Correct 208 ms 22060 KB Output is correct
4 Correct 190 ms 19864 KB Output is correct
5 Correct 213 ms 21072 KB Output is correct
6 Correct 199 ms 20392 KB Output is correct
7 Correct 214 ms 21328 KB Output is correct
8 Correct 231 ms 20032 KB Output is correct
9 Correct 199 ms 19756 KB Output is correct
10 Correct 199 ms 22352 KB Output is correct
11 Correct 190 ms 20652 KB Output is correct
12 Correct 194 ms 21584 KB Output is correct
13 Correct 195 ms 19940 KB Output is correct
14 Correct 204 ms 21840 KB Output is correct
15 Correct 205 ms 21588 KB Output is correct
16 Correct 187 ms 19540 KB Output is correct
17 Correct 198 ms 21284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 222 ms 20176 KB Output is correct
2 Correct 203 ms 22096 KB Output is correct
3 Correct 208 ms 22060 KB Output is correct
4 Correct 190 ms 19864 KB Output is correct
5 Correct 213 ms 21072 KB Output is correct
6 Correct 199 ms 20392 KB Output is correct
7 Correct 214 ms 21328 KB Output is correct
8 Correct 231 ms 20032 KB Output is correct
9 Correct 199 ms 19756 KB Output is correct
10 Correct 199 ms 22352 KB Output is correct
11 Correct 190 ms 20652 KB Output is correct
12 Correct 194 ms 21584 KB Output is correct
13 Correct 195 ms 19940 KB Output is correct
14 Correct 204 ms 21840 KB Output is correct
15 Correct 205 ms 21588 KB Output is correct
16 Correct 187 ms 19540 KB Output is correct
17 Correct 198 ms 21284 KB Output is correct
18 Correct 255 ms 20308 KB Output is correct
19 Correct 265 ms 22100 KB Output is correct
20 Correct 215 ms 22020 KB Output is correct
21 Correct 260 ms 20052 KB Output is correct
22 Correct 231 ms 20304 KB Output is correct
23 Correct 204 ms 20308 KB Output is correct
24 Correct 256 ms 20864 KB Output is correct
25 Correct 198 ms 19796 KB Output is correct
26 Correct 255 ms 19792 KB Output is correct
27 Correct 282 ms 22492 KB Output is correct
28 Correct 234 ms 20308 KB Output is correct
29 Correct 250 ms 21684 KB Output is correct
30 Correct 220 ms 19920 KB Output is correct
31 Correct 238 ms 22096 KB Output is correct
32 Correct 222 ms 21692 KB Output is correct
33 Correct 254 ms 19540 KB Output is correct
34 Correct 231 ms 21456 KB Output is correct