Submission #301652

# Submission time Handle Problem Language Result Execution time Memory
301652 2020-09-18T05:43:26 Z kevinsogo Wall (IOI14_wall) C++17
100 / 100
1139 ms 224676 KB
#include <bits/stdc++.h>
using namespace std;
#include "wall.h"

const int INF = 1 << 30;

struct window {
    int l, r;
    window(int l = -INF, int r = +INF): l(l), r(r) {
        assert(l <= r);
    }

    window operator*(const window& o) const {
        window w = *this; w *= o; return w;
    }

    window& operator*=(const window& o) {
        l = o(l); r = o(r);
        return *this;
    }

    int operator()(int v) const {
        return clamp(v, l, r);
    }
};

struct Tree {
    int i, j;
    window v;
    Tree *l, *r;
    Tree(int i, int j): i(i), j(j) {
        if (j - i == 1) {
            v = window(0, 0);
            l = r = nullptr;
        } else {
            int k = i + j >> 1;
            l = new Tree(i, k);
            r = new Tree(k, j);
        }
    }

    void visit() {
        if (l) {
            l->v *= v;
            r->v *= v;
            v = window();
        }
    }

    void chop(int I, int J, const window& w) {
        if (I <= i && j <= J) {
            v *= w;
            visit();
        } else {
            visit();
            if (!(J <= i || j <= I)) {
                l->chop(I, J, w);
                r->chop(I, J, w);
            }
        }
    }

    int *trav(int *t) {
        visit();
        if (l) {
            t = l->trav(t);
            t = r->trav(t);
        } else {
            assert(v.l == v.r);
            *(t++) = v.l;
        }
        return t;
    }
};

#define LW 1
#define HG 2

void buildWall(int n, int q, int ops[], int lfs[], int rgs[], int hts[], int finalHeight[]) {
    Tree t(0, n);
    for (int qq = 0; qq < q; qq++) {
        t.chop(lfs[qq], ++rgs[qq], ops[qq] == LW ? window(hts[qq], INF) : window(-INF , hts[qq]));
    }
    t.trav(finalHeight);
}

Compilation message

wall.cpp: In constructor 'Tree::Tree(int, int)':
wall.cpp:36:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |             int k = i + j >> 1;
      |                     ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 9 ms 1536 KB Output is correct
5 Correct 9 ms 1536 KB Output is correct
6 Correct 7 ms 1536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 179 ms 14072 KB Output is correct
3 Correct 262 ms 9208 KB Output is correct
4 Correct 968 ms 27724 KB Output is correct
5 Correct 407 ms 28792 KB Output is correct
6 Correct 380 ms 27236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 3 ms 488 KB Output is correct
3 Correct 3 ms 416 KB Output is correct
4 Correct 9 ms 1512 KB Output is correct
5 Correct 8 ms 1568 KB Output is correct
6 Correct 7 ms 1536 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 191 ms 13920 KB Output is correct
9 Correct 263 ms 9208 KB Output is correct
10 Correct 904 ms 27792 KB Output is correct
11 Correct 392 ms 28868 KB Output is correct
12 Correct 394 ms 27272 KB Output is correct
13 Correct 1 ms 416 KB Output is correct
14 Correct 184 ms 14012 KB Output is correct
15 Correct 44 ms 3192 KB Output is correct
16 Correct 978 ms 28096 KB Output is correct
17 Correct 385 ms 27388 KB Output is correct
18 Correct 389 ms 27512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 11 ms 1664 KB Output is correct
5 Correct 7 ms 1536 KB Output is correct
6 Correct 7 ms 1536 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 181 ms 14072 KB Output is correct
9 Correct 256 ms 9184 KB Output is correct
10 Correct 897 ms 27764 KB Output is correct
11 Correct 390 ms 28796 KB Output is correct
12 Correct 402 ms 27384 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 190 ms 13944 KB Output is correct
15 Correct 46 ms 3168 KB Output is correct
16 Correct 992 ms 28024 KB Output is correct
17 Correct 428 ms 27512 KB Output is correct
18 Correct 391 ms 27404 KB Output is correct
19 Correct 1127 ms 224676 KB Output is correct
20 Correct 1134 ms 222128 KB Output is correct
21 Correct 1136 ms 224564 KB Output is correct
22 Correct 1113 ms 222132 KB Output is correct
23 Correct 1109 ms 222124 KB Output is correct
24 Correct 1138 ms 222200 KB Output is correct
25 Correct 1094 ms 222200 KB Output is correct
26 Correct 1103 ms 224572 KB Output is correct
27 Correct 1139 ms 224560 KB Output is correct
28 Correct 1106 ms 222028 KB Output is correct
29 Correct 1103 ms 222124 KB Output is correct
30 Correct 1089 ms 222040 KB Output is correct