답안 #1043631

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1043631 2024-08-04T12:36:33 Z vanea 벽 (IOI14_wall) C++14
0 / 100
112 ms 8216 KB
#include <bits/stdc++.h>
#include "wall.h"
using namespace std;
using ll = long long;
using ld = long double;

const int mxN = 1e7;
const int INF = 1e9+10;

array<int, 2> st[mxN];

void build(int node, int l, int r) {
    if(l == r) {
        st[node] = {0, INF};
        return ;
    }
    int mid = (l+r)/2;
    build(node*2, l, mid);
    build(node*2+1, mid+1, r);
    st[node] = {0, INF};
}

void propagate(int node, int l, int r) {
    if(l == r) return ;
    int left = node*2, right = node*2+1;
    st[left][0] = max(st[left][0], st[node][0]);
    st[left][1] = min(st[left][1], st[node][1]);
    st[right][0] = max(st[right][0], st[node][0]);
    st[right][1] = min(st[right][1], st[node][1]);
    st[left][1] = max(st[left][1], st[node][0]);
    st[left][0] = min(st[left][0], st[node][1]);
    st[right][0] = min(st[right][0], st[node][1]);
    st[right][1] = max(st[right][1], st[node][0]);
    st[node][0] = 0; st[node][1] = INF;
}

void upd(int node, int l, int r, int l1, int r1, int h, int op) {
    propagate(node, l, r);
    if(l1 <= l && r1 >= r) {
        if(op == 1) {
            st[node][0] = max(st[node][0], h);
            st[node][1] = max(st[node][1], h);
        }
        else {
            st[node][1] = min(st[node][1], h);
            st[node][0] = min(st[node][0], h);
        }
        return ;
    }
    if(l1 > r || r1 < l) return ;
    int mid = (l+r)/2;
    upd(node*2, l, mid, l1, r1, h, op);
    upd(node*2+1, mid+1, r, l1, r1, h, op);
}

int query(int node, int l, int r, int k) {
    if(l == r && l == k) {
        return min(st[node][0], st[node][1]);
    }
    if(l > k || r < k) return 0;
    int mid = (l+r)/2;
    return query(node*2, l, mid, k) + query(node*2+1, mid+1, r, k);
}

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
    build(1, 0, n-1);
    for(int i = 0; i < k; i++) {
        upd(1, 0, n-1, left[i], right[i], height[i], op[i]);
    }
    for(int i = 0; i < n; i++) {
        finalHeight[i] = query(1, 0, n-1, i);
    }
}
/*
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int arr1[10] = {1, 2, 2, 1, 1, 2}, arr2[10] = {1, 4, 3, 0, 2, 6};
    int arr3[10] = {8, 9, 6, 5, 2, 7}, arr4[10] = {4, 1, 5, 3, 5, 0};
    int arr5[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    buildWall(10, 6, arr1, arr2, arr3, arr4, arr5);
}*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 83 ms 8216 KB Output is correct
3 Incorrect 112 ms 5968 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -