Submission #1068418

# Submission time Handle Problem Language Result Execution time Memory
1068418 2024-08-21T09:47:47 Z Ignut Meetings (IOI18_meetings) C++17
19 / 100
437 ms 392044 KB
// Ignut

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll INF = 1e18 + 123;

const int MAXN = 1e5 + 123;

// "1" segments
vector<pair<int, int>> vec;
int sz;

// maximum segment tree
int t[4 * MAXN];

void Build(int v, int l, int r) {
    if (l == r) {
        t[v] = vec[l].second - vec[l].first + 1;
        return;
    }
    int mid = l + (r - l) / 2;
    Build(v * 2, l, mid), Build(v * 2 + 1, mid + 1, r);
    t[v] = max(t[v * 2], t[v * 2 + 1]);
}

int Max(int v, int l, int r, int ql, int qr) {
    if (l > qr || ql > r)
        return 0;
    if (l >= ql && r <= qr)
        return t[v];
    int mid = l + (r - l) / 2;
    return max(Max(v * 2, l, mid, ql, qr), Max(v * 2 + 1, mid + 1, r, ql, qr));
}

vector<ll> minimum_costs(vector<int> H, vector<int> L, vector<int> R) {
    int N = H.size();
    int Q = L.size();
    if (N <= 5555 && Q <= 5555) {
        ll goLeft[N][N] = {};
        ll goRight[N][N] = {};
        for (int i = 0; i < N; i ++) {
            ll mx = H[i];
            ll sum = 0;
            for (int j = i; j >= 0; j --) {
                mx = max(mx, 1ll * H[j]);
                sum += mx;
                goLeft[i][j] = sum;
            }
            mx = H[i];
            sum = 0;
            for (int j = i; j < N; j ++) {
                mx = max(mx, 1ll * H[j]);
                sum += mx;
                goRight[i][j] = sum;
            }
        }

        vector<ll> res;
        for (int i = 0; i < Q; i ++) {
            ll ans = INF;
            for (int s = L[i]; s <= R[i]; s ++)
                ans = min(ans, goLeft[s][L[i]] + goRight[s][R[i]] - H[s]);
            res.push_back(ans);
        }
        return res;
    }
    
    vec.clear();
    int l = -1;
    for (int i = 0; i < N; i ++) {
        if (H[i] == 1) {
            if (l == -1) l = i;
        }
        else {
            if (l != -1) vec.push_back({l, i - 1});
            l = -1;
        }
    }
    if (l != -1) vec.push_back({l, N - 1});
    sz = vec.size();
    Build(1, 0, sz - 1);

    vector<ll> res;
    for (int i = 0; i < Q; i ++) {
        int l = L[i], r = R[i];
        int il = lower_bound(vec.begin(), vec.end(), make_pair(l, -1)) - vec.begin();
        int ir = upper_bound(vec.begin(), vec.end(), make_pair(r, N + 1)) - vec.begin();
        if (il == ir) {
            // cout << "I\n";
            res.push_back((r - l + 1) * 2);
            continue;
        }
        int maxCnt = min(r, vec[il].second) - max(l, vec[il].first) + 1;
        if (il + 1 == ir) {
            // cout << "II\n";
            res.push_back((r - l + 1) * 2 - maxCnt);
            continue;
        }
        // cout << "III\n";
        maxCnt = max(maxCnt, Max(1, 0, sz - 1, il + 1, ir - 1));
        res.push_back((r - l + 1) * 2 - maxCnt);
    }
    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 81 ms 141296 KB Output is correct
3 Correct 85 ms 141332 KB Output is correct
4 Correct 85 ms 141144 KB Output is correct
5 Correct 88 ms 141392 KB Output is correct
6 Correct 82 ms 141136 KB Output is correct
7 Correct 83 ms 141280 KB Output is correct
8 Correct 87 ms 141140 KB Output is correct
9 Correct 90 ms 141396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 81 ms 141296 KB Output is correct
3 Correct 85 ms 141332 KB Output is correct
4 Correct 85 ms 141144 KB Output is correct
5 Correct 88 ms 141392 KB Output is correct
6 Correct 82 ms 141136 KB Output is correct
7 Correct 83 ms 141280 KB Output is correct
8 Correct 87 ms 141140 KB Output is correct
9 Correct 90 ms 141396 KB Output is correct
10 Correct 310 ms 392044 KB Output is correct
11 Correct 437 ms 392020 KB Output is correct
12 Correct 339 ms 391988 KB Output is correct
13 Correct 434 ms 391956 KB Output is correct
14 Correct 336 ms 392016 KB Output is correct
15 Correct 338 ms 391940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 25 ms 1884 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 25 ms 1884 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 81 ms 141296 KB Output is correct
3 Correct 85 ms 141332 KB Output is correct
4 Correct 85 ms 141144 KB Output is correct
5 Correct 88 ms 141392 KB Output is correct
6 Correct 82 ms 141136 KB Output is correct
7 Correct 83 ms 141280 KB Output is correct
8 Correct 87 ms 141140 KB Output is correct
9 Correct 90 ms 141396 KB Output is correct
10 Correct 310 ms 392044 KB Output is correct
11 Correct 437 ms 392020 KB Output is correct
12 Correct 339 ms 391988 KB Output is correct
13 Correct 434 ms 391956 KB Output is correct
14 Correct 336 ms 392016 KB Output is correct
15 Correct 338 ms 391940 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Incorrect 25 ms 1884 KB Output isn't correct
18 Halted 0 ms 0 KB -