Submission #997386

# Submission time Handle Problem Language Result Execution time Memory
997386 2024-06-12T08:27:28 Z vjudge1 Measures (CEOI22_measures) C++17
100 / 100
444 ms 50096 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
#define int ll
using vi = vector<int>;
using ii = pair<int, int>;
const ll INF = 1e18;

struct AINT {
    int n;
    vi Mi, Ma, Re, Lz;

    AINT(int N) : n(N), Mi(4 * N, 0), Ma(4 * N, 0), Re(4 * N, 0), Lz(4 * N, 0) {}

    void prop(int u, int s, int d) {
        Mi[u] += Lz[u];
        Ma[u] += Lz[u];
        if(s != d) {
            Lz[u << 1] += Lz[u];
            Lz[u << 1 | 1] += Lz[u];
        }
        Lz[u] = 0;
    }

    void update(int l, int r, int v, int u, int s, int d) {
        prop(u, s, d);
        if(r < s || d < l) return;
        if(l <= s && d <= r) {
            Lz[u] += v;
            prop(u, s, d);
            return;
        }
        update(l, r, v, u << 1, s, (s + d) >> 1);
        update(l, r, v, u << 1 | 1, ((s + d) >> 1) + 1, d);

        Mi[u] = min(Mi[u << 1], Mi[u << 1 | 1]);
        Ma[u] = max(Ma[u << 1], Ma[u << 1 | 1]);
        Re[u] = max({Re[u << 1], Re[u << 1 | 1], Ma[u << 1 | 1] - Mi[u << 1]});
    }

    void update(int l, int r, int v) { update(l, r, v, 1, 0, n - 1); }

    int query() { return Re[1]; }
};

struct solver {
    int n, d, rez;
    vi V, pozInA;
    vector<ii> A;
    set<int> Active;

    AINT Sol;

    solver(int N, vi V0, int D) : n(N), d(D), rez(0), V(V0), Sol(N + 1) {
        for(int i = 0; i < n; ++i) {
            A.push_back({V[i], i});
        }
        V.push_back(-INF);
        A.push_back({-INF, n});
        ++n;
        sort(A.begin(), A.end());
        pozInA.resize(n);
        for(int i = 0; i < n; ++i)
            pozInA[A[i].second] = i;

        Active.insert(0);
    }

    void enable(int p) {
        int pA = pozInA[p];
        auto ant = *(--Active.lower_bound(pA)); /// pozitia anterioriului in A
        int dist1 = V[p] - A[ant].first, v1 = (d - dist1) / 2;
        Sol.update(pA, n, v1);

        auto urm = Active.lower_bound(pA);
        if(urm != Active.end()) {
            int purm = *urm;
            int dist2 = A[purm].first - V[p], v2 = (d - dist2) / 2;
            int dist_ant = A[purm].first - A[ant].first, vant = (d - dist_ant) / 2;
            Sol.update(purm, n, v2 - vant);
        }

        Active.insert(pA);
        rez = max(rez, Sol.query());
    }
};

signed main() {
    int n, m, d;
    cin >> n >> m >> d;

    vi V(n + m);
    d *= 2;
    for(int i = 0; i < n + m; ++i) {
        cin >> V[i];
        V[i] *= 2;
    }
    
    solver S(n + m, V, d);

    for(int i = 0; i < n; ++i) S.enable(i);

    for(int i = 0; i < m; ++i) {
        S.enable(i + n);
        int r = S.rez;
        cout << r / 2;
        if(r & 1) cout << ".5 ";
        else cout << " ";
    }
    cout << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 860 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 2 ms 704 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 2 ms 856 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 860 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 2 ms 704 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 2 ms 856 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 324 ms 42624 KB Output is correct
10 Correct 319 ms 43132 KB Output is correct
11 Correct 203 ms 42480 KB Output is correct
12 Correct 255 ms 42484 KB Output is correct
13 Correct 193 ms 44800 KB Output is correct
14 Correct 244 ms 42628 KB Output is correct
15 Correct 354 ms 42496 KB Output is correct
16 Correct 208 ms 42892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 213 ms 44536 KB Output is correct
2 Correct 220 ms 48768 KB Output is correct
3 Correct 230 ms 48768 KB Output is correct
4 Correct 214 ms 45952 KB Output is correct
5 Correct 262 ms 46720 KB Output is correct
6 Correct 221 ms 46316 KB Output is correct
7 Correct 223 ms 47464 KB Output is correct
8 Correct 215 ms 45436 KB Output is correct
9 Correct 208 ms 46212 KB Output is correct
10 Correct 220 ms 47712 KB Output is correct
11 Correct 220 ms 46980 KB Output is correct
12 Correct 218 ms 46980 KB Output is correct
13 Correct 205 ms 45440 KB Output is correct
14 Correct 220 ms 48768 KB Output is correct
15 Correct 224 ms 47156 KB Output is correct
16 Correct 200 ms 46976 KB Output is correct
17 Correct 215 ms 48000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 213 ms 44536 KB Output is correct
2 Correct 220 ms 48768 KB Output is correct
3 Correct 230 ms 48768 KB Output is correct
4 Correct 214 ms 45952 KB Output is correct
5 Correct 262 ms 46720 KB Output is correct
6 Correct 221 ms 46316 KB Output is correct
7 Correct 223 ms 47464 KB Output is correct
8 Correct 215 ms 45436 KB Output is correct
9 Correct 208 ms 46212 KB Output is correct
10 Correct 220 ms 47712 KB Output is correct
11 Correct 220 ms 46980 KB Output is correct
12 Correct 218 ms 46980 KB Output is correct
13 Correct 205 ms 45440 KB Output is correct
14 Correct 220 ms 48768 KB Output is correct
15 Correct 224 ms 47156 KB Output is correct
16 Correct 200 ms 46976 KB Output is correct
17 Correct 215 ms 48000 KB Output is correct
18 Correct 364 ms 47476 KB Output is correct
19 Correct 388 ms 47996 KB Output is correct
20 Correct 226 ms 48516 KB Output is correct
21 Correct 274 ms 45416 KB Output is correct
22 Correct 311 ms 47236 KB Output is correct
23 Correct 259 ms 45696 KB Output is correct
24 Correct 353 ms 46716 KB Output is correct
25 Correct 248 ms 45180 KB Output is correct
26 Correct 340 ms 45916 KB Output is correct
27 Correct 444 ms 50096 KB Output is correct
28 Correct 298 ms 45696 KB Output is correct
29 Correct 322 ms 49028 KB Output is correct
30 Correct 270 ms 45184 KB Output is correct
31 Correct 281 ms 48256 KB Output is correct
32 Correct 262 ms 47980 KB Output is correct
33 Correct 371 ms 46980 KB Output is correct
34 Correct 296 ms 46720 KB Output is correct