Submission #700387

# Submission time Handle Problem Language Result Execution time Memory
700387 2023-02-19T06:06:22 Z Cyanmond Wall (IOI14_wall) C++17
100 / 100
699 ms 141632 KB
#include "wall.h"
#include <bits/stdc++.h>

constexpr int inf = 500000;

struct node {
    int l;
    int r;
    // clamp(a, l, r)
};
node merge(node a, node b) {
    a.l = std::min(b.r, a.l);
    a.r = std::min(b.r, a.r);
    a.l = std::max(b.l, a.l);
    a.r = std::max(b.l, a.r);
    return a;
}
node id = {-inf, inf};

int eval(int x, node p) {
    return std::max(p.l, std::min(p.r, x));
}

class segtree {
    int n, size;
    std::vector<node> data;

    void update(int i) {
        data[i] = merge(data[2 * i], data[2 * i + 1]);
    }

    public:
    segtree(int n_) : n(n_) {
        size = 1;
        while (size < n) {
            size *= 2;
        }
        data.assign(2 * size, id);
    }

    void edit(int i, node v) {
        i += size;
        data[i] = v;
        while (i != 1) {
            i /= 2;
            update(i);
        }
    }

    node foldAll() {
        return data[1];
    }
};

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
    std::vector<std::vector<int>> addList(n + 1), eraseList(n + 1);
    for (int i = 0; i < k; ++i) {
        addList[left[i]].push_back(i);
        eraseList[right[i] + 1].push_back(i);
    }
    segtree seg(k);
    for (int i = 0; i < n; ++i) {
        for (const int x : addList[i]) {
            if (op[x] == 1) {
                seg.edit(x, {height[x], inf});
            } else {
                seg.edit(x, {-inf, height[x]});
            }
        }
        for (const int x : eraseList[i]) {
            seg.edit(x, id);
        }

        const auto res = seg.foldAll();
        finalHeight[i] = eval(0, res);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 4 ms 596 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 6 ms 1236 KB Output is correct
5 Correct 6 ms 1108 KB Output is correct
6 Correct 4 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 211 ms 20400 KB Output is correct
3 Correct 166 ms 11780 KB Output is correct
4 Correct 520 ms 30800 KB Output is correct
5 Correct 283 ms 28664 KB Output is correct
6 Correct 305 ms 28308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 5 ms 1236 KB Output is correct
5 Correct 4 ms 1108 KB Output is correct
6 Correct 5 ms 1152 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 206 ms 20408 KB Output is correct
9 Correct 202 ms 11916 KB Output is correct
10 Correct 699 ms 30840 KB Output is correct
11 Correct 319 ms 28696 KB Output is correct
12 Correct 251 ms 28308 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 258 ms 20448 KB Output is correct
15 Correct 28 ms 2916 KB Output is correct
16 Correct 623 ms 30852 KB Output is correct
17 Correct 300 ms 28272 KB Output is correct
18 Correct 296 ms 28000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 6 ms 1236 KB Output is correct
5 Correct 4 ms 1108 KB Output is correct
6 Correct 5 ms 1128 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 188 ms 20480 KB Output is correct
9 Correct 169 ms 11896 KB Output is correct
10 Correct 576 ms 30840 KB Output is correct
11 Correct 280 ms 28696 KB Output is correct
12 Correct 285 ms 28256 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 281 ms 20448 KB Output is correct
15 Correct 39 ms 2960 KB Output is correct
16 Correct 587 ms 30808 KB Output is correct
17 Correct 291 ms 28336 KB Output is correct
18 Correct 282 ms 28040 KB Output is correct
19 Correct 621 ms 141616 KB Output is correct
20 Correct 558 ms 141528 KB Output is correct
21 Correct 658 ms 141516 KB Output is correct
22 Correct 565 ms 141548 KB Output is correct
23 Correct 606 ms 141600 KB Output is correct
24 Correct 586 ms 141568 KB Output is correct
25 Correct 662 ms 141516 KB Output is correct
26 Correct 561 ms 141520 KB Output is correct
27 Correct 595 ms 141624 KB Output is correct
28 Correct 636 ms 141516 KB Output is correct
29 Correct 640 ms 141612 KB Output is correct
30 Correct 580 ms 141632 KB Output is correct