답안 #1035026

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1035026 2024-07-26T03:11:53 Z TrinhKhanhDung 벽 (IOI14_wall) C++14
0 / 100
139 ms 21832 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ALL(v) v.begin(),v.end()
#define MASK(k) (1LL << (k))
#define BIT(x, i) (((x) >> (i)) & 1)
#define oo (ll)1e18
#define INF (ll)1e9
#define MOD (ll)(1e9 + 7)

#include "wall.h"

using namespace std;

template<class T1, class T2>
    bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}

template<class T1, class T2>
    bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}

template<class T1, class T2>
    void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;}

template<class T1, class T2>
    void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;}

template<class T>
    void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}

struct SegmentTree{
    vector<int> up, down;
    int n;

    SegmentTree(int _n = 0){
        n = _n;
        up.resize(4 * n + 3, 0);
        down.resize(4 * n + 3);
        for(int i=1; i<=4*n; i++){
            down[i] = n + 1;
        }
    }

    void push(int i){
        maximize(up[i * 2], up[i]);
        maximize(up[i * 2 + 1], up[i]);
        minimize(down[i * 2], down[i]);
        minimize(down[i * 2 + 1], down[i]);
        minimize(up[i * 2], down[i]);
        minimize(up[i * 2 + 1], down[i]);
        maximize(down[i * 2], up[i]);
        maximize(down[i * 2 + 1], up[i]);

        up[i] = 0;
        down[i] = n + 1;
    }

    void update(int i, int l, int r, int u, int v, int h, int t){
        if(r < u || v < l) return;
        if(u <= l && r <= v){
            if(t == 1){
                maximize(up[i], h);
                maximize(down[i], h);
            }
            else{
                minimize(down[i], h);
                minimize(up[i], h);
            }
            return;
        }
        push(i);
        int m = (l + r) >> 1;
        update(i * 2, l, m, u, v, h, t);
        update(i * 2 + 1, m + 1, r, u, v, h, t);
    }

    void update(int u, int v, int h, int t){
        update(1, 0, n-1, u, v, h, t);
    }

    int getVal(int p){
        int i = 1, l = 0, r = n-1;
        while(l < r){
            int m = (l + r) >> 1;
            push(i);
            if(p <= m){
                i = i * 2;
                r = m;
            }
            else{
                i = i * 2 + 1;
                l = m + 1;
            }
        }
        return up[i];
    }
};

const int MAX = 2e6 + 10;

int N, Q;
int t[MAX], L[MAX], R[MAX], H[MAX];

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
    N = n;
    Q = k;
    for(int i=0; i<Q; i++){
        t[i] = op[i];
        L[i] = left[i];
        R[i] = right[i];
        H[i] = height[i];
    }

    SegmentTree IT(n);
    for(int i=0; i<Q; i++){
        IT.update(L[i], R[i], H[i], t[i]);
    }
    for(int i=0; i<N; i++){
        finalHeight[i] = IT.getVal(i);
    }
}

//signed main(){
//    ios_base::sync_with_stdio(0); cin.tie(0);
   // freopen("task.inp", "r", stdin);
   // freopen("task.out", "w", stdout);

//    cin >> N >> Q;
//    SegmentTree IT(N);
//    for(int i=1; i<=Q; i++){
//        int l, r, h, t;
//        cin >> l >> r >> h >> t;
//        IT.update(l, r, h, t);
//        for(int j=0; j<N; j++){
//            cout << IT.getVal(j) << ' ';
//        }
//        cout << '\n';
//    }

//    return 0;
//}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 604 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 84 ms 21832 KB Output is correct
3 Incorrect 139 ms 12624 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -