제출 #485564

#제출 시각아이디문제언어결과실행 시간메모리
485564Mazaalai벽 (IOI14_wall)C++14
61 / 100
535 ms31300 KiB
#include "wall.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int M = 4 * N;
struct Node {
    int mini, maxi, lazy;
    Node() {
        mini = maxi = 0;
        lazy = -1;
    }
    void setMinMax(int a, int b) {
        mini = a, maxi = b;
    }
};
vector <int> ans(N);
vector <Node> node(M);
void propagate(int head) {
    if (node[head].lazy == -1) return;
    int val = node[head].lazy;
    node[head].lazy = -1;
    node[head*2+1].setMinMax(val, val);
    node[head*2+2].setMinMax(val, val);
    node[head*2+1].lazy = val;
    node[head*2+2].lazy = val;
}
void update(int l, int r, int L, int R, int val, bool type, int head) {
    if ((l > R) || 
        (L > r) ||
        (type && node[head].mini >= val) ||
        (!type && node[head].maxi <= val)
    ) return;
    if (L <= l && r <= R && node[head].mini == node[head].maxi) {
        node[head].setMinMax(val, val);
        node[head].lazy = val;
        return;
    }
    propagate(head);

    int mid = (l+r)>>1;
    update(l, mid, L, R, val, type, head*2+1);
    update(mid+1, r, L, R, val, type, head*2+2);
    node[head].setMinMax(
        min(node[head*2+1].mini, node[head*2+2].mini),
        max(node[head*2+1].maxi, node[head*2+2].maxi)
    );

}
void dfs(int l, int r, int head) {
    if (l == r) {
        ans[l] = node[head].mini;
        return;
    }
    propagate(head);
    int mid = (l+r)>>1;
    dfs(l, mid, head*2+1);
    dfs(mid+1, r, head*2+2);
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
    // segmentTree (0, 1, 2, ... n)
    // k = number of operations
    // op, left, right, height -> operation = 1 ? add : remove, l, r, val
    // change values of finalHeight
    for (int i = 0; i < k; i++) {
        // update(l, r,   L,       R,        val,       type,            head)
        update(0, n-1, left[i], right[i], height[i], (op[i]==1?1:0), 0);
    }
    dfs(0, n-1, 0);
    for (int i = 0; i < n; i++) finalHeight[i] = ans[i];
    return;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...