답안 #1007653

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1007653 2024-06-25T09:47:29 Z farrellw 벽 (IOI14_wall) C++14
100 / 100
398 ms 48916 KB
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define INF 100005
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
 
#include "wall.h"
 
ii combine(ii upd_new, ii upd_old) {    // apply upd_new to upd_old
    ii res = {max(upd_new.fi, upd_old.fi), min(upd_new.se, upd_old.se)};
    if (res.fi > res.se) { // The ranges are disjoint, so suffices to check either
        return (upd_old.se < upd_new.se) ? make_pair(upd_new.fi, upd_new.fi) : make_pair(upd_new.se, upd_new.se);
    }
    return res;
}
 
struct Segtree {    // Segtree of updates
    int sz;
    vector<ii> upd;    // store (a, b)
    Segtree(int N) {
        sz = 1;
        while (sz < N)
            sz *= 2;
        upd = vii(2 * sz, {0, INF});
    }
    void push(int id) { // O(1), for regular updates
        if (id+1 >= sz)
            return;
        upd[(id<<1)|1] = combine(upd[id], upd[(id<<1)|1]);
        upd[2 * id + 2] = combine(upd[id], upd[2 * id + 2]);
        upd[id] = {0, INF};
    }
 
    void push_recursive() { // O(N), only for answer extraction at the end
        for(int id=0; id < sz-1; id++) {
            push(id);
        }
    }
 
    void range_upd(int qleft, int qright, ii val, int id, int left, int right) {
        if (qleft <= left && right <= qright) {
            upd[id] = combine(val, upd[id]);
            return;
        }
        if (qright <= left || right <= qleft)
            return;
        push(id);
        int mid = (left + right)>>1;
        range_upd(qleft, qright, val, (id<<1)|1, left, mid);
        range_upd(qleft, qright, val, 2 * id + 2, mid, right);
    }
    void range_upd(int qleft, int qright, ii val) {
        range_upd(qleft, qright, val, 0, 0, sz);
    }
};
 
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
    Segtree tree(n);
    for(int z = 0; z < k; z++) {
        ii upd_val = (op[z] == 1) ? make_pair(height[z], INF) : make_pair(0, height[z]);
        tree.range_upd(left[z], right[z]+1, upd_val);
    }
    tree.push_recursive();
    for(int z = 0; z < n; z++) {
        finalHeight[z] = tree.upd[z+tree.sz-1].fi;
    }
    return;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 4 ms 604 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 3 ms 804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 76 ms 8160 KB Output is correct
3 Correct 104 ms 4176 KB Output is correct
4 Correct 361 ms 10576 KB Output is correct
5 Correct 160 ms 10536 KB Output is correct
6 Correct 179 ms 10576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 4 ms 604 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 80 ms 8160 KB Output is correct
9 Correct 101 ms 4176 KB Output is correct
10 Correct 327 ms 10580 KB Output is correct
11 Correct 179 ms 10576 KB Output is correct
12 Correct 155 ms 10580 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 76 ms 8244 KB Output is correct
15 Correct 23 ms 1372 KB Output is correct
16 Correct 398 ms 10576 KB Output is correct
17 Correct 172 ms 10580 KB Output is correct
18 Correct 164 ms 10580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 4 ms 604 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 72 ms 8096 KB Output is correct
9 Correct 101 ms 4044 KB Output is correct
10 Correct 350 ms 10548 KB Output is correct
11 Correct 153 ms 10648 KB Output is correct
12 Correct 161 ms 10580 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 79 ms 8080 KB Output is correct
15 Correct 23 ms 1368 KB Output is correct
16 Correct 372 ms 10608 KB Output is correct
17 Correct 171 ms 10712 KB Output is correct
18 Correct 182 ms 10612 KB Output is correct
19 Correct 351 ms 48824 KB Output is correct
20 Correct 363 ms 48724 KB Output is correct
21 Correct 365 ms 48784 KB Output is correct
22 Correct 330 ms 48720 KB Output is correct
23 Correct 330 ms 48916 KB Output is correct
24 Correct 362 ms 48908 KB Output is correct
25 Correct 341 ms 48700 KB Output is correct
26 Correct 357 ms 48724 KB Output is correct
27 Correct 363 ms 48724 KB Output is correct
28 Correct 352 ms 48720 KB Output is correct
29 Correct 355 ms 48824 KB Output is correct
30 Correct 354 ms 48720 KB Output is correct