Submission #1043462

# Submission time Handle Problem Language Result Execution time Memory
1043462 2024-08-04T09:47:04 Z deera Wall (IOI14_wall) C++14
0 / 100
126 ms 8256 KB
// ioi 2014
// Day 2: Wall
#include <bits/stdc++.h>
using namespace std;


struct Op {
    public:
        int t, v;
        Op(int t, int v) : t(t), v(v) {}
};
class Tree {
    public:
        const int N;
        vector<pair<int, int>> tree;

        Tree(int n): N(n) {
            tree.resize(n * 4, {0, INT_MAX - 1});
        }


        void laze(int x, Op op) {
            if (op.t == 1) {
                tree[x].first = max(tree[x].first, op.v);
                tree[x].second = max(tree[x].first, tree[x].second);
            } else {
                tree[x].first = min(tree[x].first, tree[x].second);
                tree[x].second = min(tree[x].second, op.v);
            }
        }

        void push(int x, int l, int r) {
            if (l == r) return;

            l = x * 2;
            r = l + 1;
            laze(l, Op(1, tree[x].first));
            laze(l, Op(2, tree[x].second));
            laze(r, Op(1, tree[x].first));
            laze(r, Op(2, tree[x].second));

            tree[x] = {0, INT_MAX - 1};
        }

        void output(int x, int l, int r, int results[]) {
            if (l == r) {
                results[l] = tree[x].first;
                return;
            }

            push(x, l, r);

            int m = (l + r) / 2;

            output(x * 2, l, m, results);
            output(x * 2 + 1, m + 1, r, results);
        }

        void update(int x, int l, int r, int a, int b, Op op) {
            if (r < a || b < l) return;
            if (a <= l && r <= b) {
                laze(x, op);
            } else {
                push(x, l, r);
                
                int m = (l + r) / 2;
                update(x * 2, l, m, a, b, op);
                update(x * 2 + 1, m + 1, r, a, b, op);
            }
        }
};

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
    // // subtask 1
    // if (n <= 10000 && k <= 5000) {
    //     for (int i = 0; i < k; i++) {
    //         if (op[i] == 1) {
    //             for (int j = left[i]; j <= right[i]; j++)
    //                 finalHeight[j] = max(finalHeight[j], height[i]);
    //         } else {
    //             for (int j = left[i]; j <= right[i]; j++)
    //                 finalHeight[j] = min(finalHeight[j], height[i]);
    //         }
    //     }
    //     return;
    // }

    Tree tree(n);
    for(int i = 0; i < k; i++) {
        tree.update(1, 0, n - 1, left[i], right[i], Op(op[i], height[i]));
    }

    tree.output(1, 0, n - 1, finalHeight);
    
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 101 ms 8256 KB Output is correct
3 Incorrect 126 ms 4176 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -