Submission #546385

# Submission time Handle Problem Language Result Execution time Memory
546385 2022-04-07T12:25:34 Z alextodoran Wall (IOI14_wall) C++17
100 / 100
655 ms 107136 KB
#include <bits/stdc++.h>

using namespace std;

const int N_MAX = 2000000;

struct SGTInfo {
    int lazyMin, lazyMax;
    SGTInfo () {
        lazyMin = INT_MIN;
        lazyMax = INT_MAX;
    }
    void update (int newMin, int newMax) {
        if (newMax < lazyMin) {
            lazyMin = lazyMax = newMax;
        } else if (lazyMax < newMin) {
            lazyMin = lazyMax = newMin;
        } else {
            lazyMin = max(lazyMin, newMin);
            lazyMax = min(lazyMax, newMax);
        }
    }
};

SGTInfo SGT[N_MAX * 4 + 2];

void build (int node, int l, int r) {
    SGT[node] = SGTInfo();
    if (l == r) {
        SGT[node].update(0, 0);
    } else {
        int mid = (l + r) / 2;
        int lSon = node * 2, rSon = node * 2 + 1;
        build(lSon, l, mid);
        build(rSon, mid + 1, r);
    }
}
void split (int node) {
    int lSon = node * 2, rSon = node * 2 + 1;
    SGT[lSon].update(SGT[node].lazyMin, SGT[node].lazyMax);
    SGT[rSon].update(SGT[node].lazyMin, SGT[node].lazyMax);
    SGT[node] = SGTInfo();
}
void update (int node, int l, int r, int ul, int ur, int utype, int uval) {
    if (ul <= l && r <= ur) {
        if (utype == 1) {
            SGT[node].update(uval, INT_MAX);
        } else {
            SGT[node].update(INT_MIN, uval);
        }
    } else {
        int mid = (l + r) / 2;
        int lSon = node * 2, rSon = node * 2 + 1;
        split(node);
        if (ul <= mid) {
            update(lSon, l, mid, ul, ur, utype, uval);
        }
        if (mid + 1 <= ur) {
            update(rSon, mid + 1, r, ul, ur, utype, uval);
        }
    }
}
int answer[N_MAX];
void getAnswer (int node, int l, int r) {
    if (l == r) {
        answer[l] = SGT[node].lazyMin;
    } else {
        int mid = (l + r) / 2;
        int lSon = node * 2, rSon = node * 2 + 1;
        split(node);
        getAnswer(lSon, l, mid);
        getAnswer(rSon, mid + 1, r);
    }
}

void buildWall (int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
    build(1, 0, n - 1);
    for (int i = 0; i < k; i++) {
        update(1, 0, n - 1, left[i], right[i], op[i], height[i]);
    }
    getAnswer(1, 0, n - 1);
    copy(answer, answer + n, finalHeight);
}
# Verdict Execution time Memory Grader output
1 Correct 27 ms 62796 KB Output is correct
2 Correct 29 ms 62944 KB Output is correct
3 Correct 31 ms 62924 KB Output is correct
4 Correct 36 ms 63220 KB Output is correct
5 Correct 37 ms 63144 KB Output is correct
6 Correct 32 ms 63208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 62916 KB Output is correct
2 Correct 151 ms 76512 KB Output is correct
3 Correct 216 ms 70152 KB Output is correct
4 Correct 399 ms 81284 KB Output is correct
5 Correct 290 ms 82352 KB Output is correct
6 Correct 303 ms 80792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 62812 KB Output is correct
2 Correct 31 ms 63012 KB Output is correct
3 Correct 30 ms 63064 KB Output is correct
4 Correct 35 ms 63200 KB Output is correct
5 Correct 35 ms 63156 KB Output is correct
6 Correct 41 ms 63116 KB Output is correct
7 Correct 28 ms 62908 KB Output is correct
8 Correct 155 ms 76476 KB Output is correct
9 Correct 183 ms 70140 KB Output is correct
10 Correct 399 ms 81296 KB Output is correct
11 Correct 301 ms 82380 KB Output is correct
12 Correct 279 ms 80800 KB Output is correct
13 Correct 29 ms 62912 KB Output is correct
14 Correct 182 ms 76492 KB Output is correct
15 Correct 59 ms 64160 KB Output is correct
16 Correct 493 ms 81520 KB Output is correct
17 Correct 291 ms 80944 KB Output is correct
18 Correct 267 ms 80956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 62884 KB Output is correct
2 Correct 33 ms 62992 KB Output is correct
3 Correct 31 ms 62920 KB Output is correct
4 Correct 35 ms 63188 KB Output is correct
5 Correct 33 ms 63120 KB Output is correct
6 Correct 35 ms 63164 KB Output is correct
7 Correct 30 ms 62880 KB Output is correct
8 Correct 166 ms 76564 KB Output is correct
9 Correct 167 ms 70144 KB Output is correct
10 Correct 398 ms 81264 KB Output is correct
11 Correct 284 ms 82344 KB Output is correct
12 Correct 271 ms 80808 KB Output is correct
13 Correct 30 ms 62932 KB Output is correct
14 Correct 164 ms 76596 KB Output is correct
15 Correct 56 ms 64136 KB Output is correct
16 Correct 534 ms 81520 KB Output is correct
17 Correct 277 ms 80980 KB Output is correct
18 Correct 263 ms 80924 KB Output is correct
19 Correct 645 ms 107136 KB Output is correct
20 Correct 655 ms 104544 KB Output is correct
21 Correct 644 ms 107052 KB Output is correct
22 Correct 615 ms 104784 KB Output is correct
23 Correct 618 ms 104620 KB Output is correct
24 Correct 619 ms 104780 KB Output is correct
25 Correct 631 ms 104616 KB Output is correct
26 Correct 622 ms 107136 KB Output is correct
27 Correct 613 ms 107112 KB Output is correct
28 Correct 631 ms 104612 KB Output is correct
29 Correct 620 ms 104616 KB Output is correct
30 Correct 610 ms 104528 KB Output is correct