Submission #713712

# Submission time Handle Problem Language Result Execution time Memory
713712 2023-03-22T21:20:42 Z thimote75 Wall (IOI14_wall) C++14
100 / 100
1593 ms 59312 KB
#include "wall.h"
#include <bits/stdc++.h>
using namespace std;

#define INF 1e9

struct SGD {
    int min_v = 0;
    int max_v = INF;

    int to (int x) {
        return max(min_v, min(max_v, x));
    }
    void combine (SGD &upper) {
        min_v = upper.to(min_v);
        max_v = upper.to(max_v);
    }
    void reset () {
        min_v = 0;
        max_v = INF;
    }
};

struct SegTree {
    vector<SGD> tree;

    int size, start, height;
    SegTree (int _size) {
        size = _size;

        height = ceil(log2(size));
        start  = 1 << height;

        tree.resize(start << 1);

        for (int i = 0; i < start; i ++)
            tree[i + start].max_v = 0;
    }

    void update (int index) {
        if (index == 0)     return ;
        
        update (index >> 1);
        if (index >= start) return ;

        int n0 = index << 1;
        int n1 = n0 + 1;

        tree[n0].combine(tree[index]);
        tree[n1].combine(tree[index]);
        tree[index].reset();
    }
    void set_min (int index, int min_v) {
        update(index);

        tree[index].min_v = max(tree[index].min_v, min_v);
        if (tree[index].max_v < tree[index].min_v)
            tree[index].max_v = tree[index].min_v;
    }
    void set_max (int index, int max_v) {
        update(index);

        tree[index].max_v = min(tree[index].max_v, max_v);
        if (tree[index].min_v > tree[index].max_v)
            tree[index].min_v = tree[index].max_v;
    }

    void set_min (int left, int right, int min_v) {
        left += start; right += start;

        while (left < right) {
            if ((left  & 1) == 1) set_min(left,  min_v);
            if ((right & 1) == 0) set_min(right, min_v);

            left  = (left  + 1) >> 1;
            right = (right - 1) >> 1;
        }

        if (left == right) set_min(left, min_v);
    }
    void set_max (int left, int right, int max_v) {
        left += start; right += start;

        while (left < right) {
            if ((left  & 1) == 1) set_max(left,  max_v);
            if ((right & 1) == 0) set_max(right, max_v);

            left  = (left  + 1) >> 1;
            right = (right - 1) >> 1;
        }

        if (left == right) set_max(left, max_v);
    }

    int res (int index, int height) {
        index += start;
        update(index);

        return tree[index].to(height);
    }

    void show (SGD &s) {
        if (s.min_v == -INF) cout << "-";
        else cout << s.min_v;
        cout << ":";
        if (s.max_v == +INF) cout << "+";
        else cout << s.max_v;
        cout << " ";
    }
    void show () {
        for (int h = 0; h <= height; h ++) {
            int s = 1 << h;

            for (int i = 0; i < s; i ++) {
                show(tree[i + s]);
            }
            cout << endl;
        }
    }
    SGD compile (int index) {
        if (index == 0) return SGD();

        SGD upper = compile(index >> 1);
        SGD curr  = tree[index];
        curr.combine(upper);

        return curr;
    }
    void ushow () {
        for (int i = 0; i < start; i ++) {
            int j = i + start;
            SGD v = compile(j);
            show(v);
        }
        cout << endl;
    }
};
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
    SegTree tree(n);

    for (int i = 0; i < k; i ++) {
        if (op[i] == 1) {
            tree.set_min( left[i], right[i], height[i] );
        } else tree.set_max( left[i], right[i], height[i] );

        //for (int l = left[i]; l <= right[i]; l ++) {
        //    if (op[i] == 1) finalHeight[l] = max(finalHeight[l], height[i]);
        //    else finalHeight[l] = min(finalHeight[l], height[i]);
        //}
    }

    for (int i = 0; i < n; i ++) {
        //cout << finalHeight[i] << " ";
        finalHeight[i] = tree.res(i, 0);
    }
    //cout << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 9 ms 596 KB Output is correct
5 Correct 7 ms 596 KB Output is correct
6 Correct 7 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 133 ms 8128 KB Output is correct
3 Correct 266 ms 4124 KB Output is correct
4 Correct 814 ms 10464 KB Output is correct
5 Correct 316 ms 20720 KB Output is correct
6 Correct 347 ms 19188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 9 ms 596 KB Output is correct
5 Correct 9 ms 596 KB Output is correct
6 Correct 9 ms 596 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 133 ms 8080 KB Output is correct
9 Correct 263 ms 4172 KB Output is correct
10 Correct 874 ms 10572 KB Output is correct
11 Correct 346 ms 20796 KB Output is correct
12 Correct 345 ms 19096 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 139 ms 13860 KB Output is correct
15 Correct 44 ms 1880 KB Output is correct
16 Correct 877 ms 20092 KB Output is correct
17 Correct 355 ms 19596 KB Output is correct
18 Correct 312 ms 19608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 12 ms 596 KB Output is correct
5 Correct 7 ms 596 KB Output is correct
6 Correct 9 ms 596 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 132 ms 8120 KB Output is correct
9 Correct 258 ms 4116 KB Output is correct
10 Correct 834 ms 10568 KB Output is correct
11 Correct 346 ms 20704 KB Output is correct
12 Correct 308 ms 19172 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 150 ms 13900 KB Output is correct
15 Correct 44 ms 1884 KB Output is correct
16 Correct 853 ms 20180 KB Output is correct
17 Correct 306 ms 19532 KB Output is correct
18 Correct 306 ms 19604 KB Output is correct
19 Correct 1593 ms 59160 KB Output is correct
20 Correct 1563 ms 59312 KB Output is correct
21 Correct 1565 ms 59144 KB Output is correct
22 Correct 1555 ms 59204 KB Output is correct
23 Correct 1578 ms 59184 KB Output is correct
24 Correct 1520 ms 59212 KB Output is correct
25 Correct 1548 ms 59108 KB Output is correct
26 Correct 1564 ms 59200 KB Output is correct
27 Correct 1570 ms 59272 KB Output is correct
28 Correct 1535 ms 59272 KB Output is correct
29 Correct 1564 ms 59196 KB Output is correct
30 Correct 1544 ms 59180 KB Output is correct