답안 #537627

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
537627 2022-03-15T10:02:49 Z happypotato 벽 (IOI14_wall) C++17
100 / 100
710 ms 134864 KB
#include "wall.h"
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define ff first
#define ss second

const int mxN = 2e6 + 1;
int seg[4 * mxN];
pii lazy[4 * mxN];
bool marked[4 * mxN];
int n;
pii merge(pii a, pii b) {
    if (min({a.ff, a.ss, b.ff, b.ss}) == -1 || max({a.ff, a.ss, b.ff, b.ss}) == 1e5 + 1) {
        a.ff = max(a.ff, b.ff);
        a.ss = min(a.ss, b.ss);
        if (a.ff > a.ss) {
            if (b.ff > a.ss) return {b.ff, b.ff};
            else if (b.ss < a.ff) return {b.ss, b.ss};
        }
        return a;
    }
    if (a.ss < b.ff) {
        return {b.ff, b.ff};
    } else if (b.ss < a.ff) {
        return {b.ss, b.ss};
    }
    a.ff = max(a.ff, b.ff);
    a.ss = min(a.ss, b.ss);
    if (a.ff > a.ss) {
        if (b.ff > a.ss) return {b.ff, b.ff};
        else if (b.ss < a.ff) return {b.ss, b.ss};
    }
    return a;
}
void pushdown(int idx) {
    if (marked[idx]) {
        seg[(idx << 1)] = max(seg[(idx << 1)], lazy[idx].ff);
        seg[(idx << 1)] = min(seg[(idx << 1)], lazy[idx].ss);
        seg[(idx << 1) + 1] = max(seg[(idx << 1) + 1], lazy[idx].ff);
        seg[(idx << 1) + 1] = min(seg[(idx << 1) + 1], lazy[idx].ss);
        lazy[(idx << 1)] = merge(lazy[(idx << 1)], lazy[idx]);
        lazy[(idx << 1) + 1] = merge(lazy[(idx << 1) + 1], lazy[idx]);
        lazy[idx] = {-1, 1e6 + 1};
        marked[(idx << 1)] = true;
        marked[(idx << 1) + 1] = true;
        marked[idx] = false;
    }
}
void update(int tl, int tr, bool ismin, int val, int l = 1, int r = n, int idx = 1) {
    if (l > r) return;
    if (tl <= l && r <= tr) {
        if (ismin) {
            seg[idx] = min(seg[idx], val);
            lazy[idx].ss = min(lazy[idx].ss, val);
            if (lazy[idx].ff > lazy[idx].ss) {
                lazy[idx].ff = lazy[idx].ss;
            }
        } else {
            seg[idx] = max(seg[idx], val);
            lazy[idx].ff = max(lazy[idx].ff, val);
            if (lazy[idx].ff > lazy[idx].ss) {
                lazy[idx].ss = lazy[idx].ff;
            }
        }
        marked[idx] = true;
        return;
    }
    pushdown(idx);
    int mid = (l + r) >> 1;
    if (tl <= mid) update(tl, min(tr, mid), ismin, val, l, mid, (idx << 1));
    if (tr > mid) update(max(tl, mid + 1), tr, ismin, val, mid + 1, r, (idx << 1) + 1);

    return;
}
int query(int tar, int l = 1, int r = n, int idx = 1) {
    if (l > r) return -1;
    if (l == r) return seg[idx];
    pushdown(idx);
    int mid = (l + r) >> 1;
    if (tar <= mid) return query(tar, l, mid, (idx << 1));
    else return query(tar, mid + 1, r, (idx << 1) + 1);
}

void buildWall(int N, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
    n = N;
    for (int i = 0; i < 4 * mxN; i++) {
        seg[i] = 0;
        lazy[i] = {-1, 1e6 + 1};
    }
    for (int i = 0; i < k; i++) {
        update(left[i] + 1, right[i] + 1, (op[i] == 2), height[i]);
    }
    for (int i = 0; i < n; i++) {
        finalHeight[i] = query(i + 1);
    }
    return;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 94156 KB Output is correct
2 Correct 47 ms 94284 KB Output is correct
3 Correct 44 ms 94284 KB Output is correct
4 Correct 51 ms 94496 KB Output is correct
5 Correct 55 ms 94500 KB Output is correct
6 Correct 51 ms 94400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 94208 KB Output is correct
2 Correct 184 ms 107784 KB Output is correct
3 Correct 264 ms 101392 KB Output is correct
4 Correct 583 ms 112472 KB Output is correct
5 Correct 282 ms 113604 KB Output is correct
6 Correct 264 ms 111968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 94284 KB Output is correct
2 Correct 47 ms 94364 KB Output is correct
3 Correct 45 ms 94228 KB Output is correct
4 Correct 50 ms 94520 KB Output is correct
5 Correct 46 ms 94424 KB Output is correct
6 Correct 49 ms 94428 KB Output is correct
7 Correct 52 ms 94156 KB Output is correct
8 Correct 183 ms 107880 KB Output is correct
9 Correct 273 ms 101472 KB Output is correct
10 Correct 612 ms 112440 KB Output is correct
11 Correct 281 ms 113532 KB Output is correct
12 Correct 287 ms 111972 KB Output is correct
13 Correct 46 ms 94156 KB Output is correct
14 Correct 183 ms 107888 KB Output is correct
15 Correct 87 ms 95416 KB Output is correct
16 Correct 710 ms 112780 KB Output is correct
17 Correct 273 ms 112264 KB Output is correct
18 Correct 274 ms 112208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 94156 KB Output is correct
2 Correct 46 ms 94256 KB Output is correct
3 Correct 54 ms 94204 KB Output is correct
4 Correct 54 ms 94556 KB Output is correct
5 Correct 49 ms 94412 KB Output is correct
6 Correct 47 ms 94456 KB Output is correct
7 Correct 44 ms 94156 KB Output is correct
8 Correct 181 ms 107804 KB Output is correct
9 Correct 262 ms 101468 KB Output is correct
10 Correct 599 ms 112532 KB Output is correct
11 Correct 279 ms 113536 KB Output is correct
12 Correct 274 ms 112032 KB Output is correct
13 Correct 45 ms 94156 KB Output is correct
14 Correct 183 ms 107884 KB Output is correct
15 Correct 87 ms 95464 KB Output is correct
16 Correct 705 ms 112728 KB Output is correct
17 Correct 284 ms 112144 KB Output is correct
18 Correct 272 ms 112204 KB Output is correct
19 Correct 692 ms 134864 KB Output is correct
20 Correct 682 ms 132180 KB Output is correct
21 Correct 690 ms 134640 KB Output is correct
22 Correct 672 ms 132252 KB Output is correct
23 Correct 674 ms 132280 KB Output is correct
24 Correct 696 ms 132172 KB Output is correct
25 Correct 674 ms 132400 KB Output is correct
26 Correct 687 ms 134736 KB Output is correct
27 Correct 677 ms 134728 KB Output is correct
28 Correct 668 ms 132172 KB Output is correct
29 Correct 707 ms 132152 KB Output is correct
30 Correct 674 ms 132140 KB Output is correct