답안 #947578

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
947578 2024-03-16T13:31:58 Z steveonalex 벽 (IOI14_wall) C++11
24 / 100
394 ms 23460 KB
#include <bits/stdc++.h>
#include "wall.h"

using namespace std;

 
typedef long long ll;
typedef unsigned long long ull;
 
#define MASK(i) (1ULL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
 
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
 
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ll mask){return __builtin_ctzll(mask);}
int logOf(ll mask){return 63 - __builtin_clzll(mask);}
 
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
 
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 T>
    void printArr(T& container, string separator = " ", string finish = "\n", ostream &out = cout){
        for(auto item: container) out << item << separator;
        out << finish;
    }
 
template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

struct SegmentTree{
    struct Node{
        int time, op, h;
        Node(int _time = -1, int _op = -1, int _h = -1){
            time = _time, op = _op, h = _h;
        }
    };
    int n;
    vector<pair<Node, Node>> a;

    SegmentTree(int _n){
        n = _n;
        a.resize(n * 2 + 2);
    }

    pair<Node, Node> combine(pair<Node, Node> a, pair<Node, Node> b){
        Node sigma_duck[] = {a.first, a.second, b.first, b.second};
        sort(sigma_duck, sigma_duck + 4, [] (Node a, Node b){return a.time < b.time;});
        pair<Node, Node> ans;
        for(Node i: sigma_duck){
            if (i.time == -1) continue;
            if (i.op == 1){
                if (maximize(ans.first.h, i.h)) {
                    ans.first = i;
                    if (ans.second.time != -1) maximize(ans.second.h, i.h);
                }
            }   
            else{
                if (ans.second.h == -1 || minimize(ans.second.h, i.h)) {
                    ans.second = i;
                    if (ans.first.time != -1) minimize(ans.first.h, i.h);
                }
            }
        }
        return ans;
    }

    void update(int l, int r, int t, int op, int h){
        pair<Node, Node> cur;
        if (op == 1) cur.first = Node(t, op, h);
        else cur.second = Node(t, op, h);
        l += n; r += n + 1;
        while(l < r){
            if (l & 1) {
                a[l] = combine(a[l], cur);
                l++;
            }
            if (r & 1){
                r--;
                a[r] = combine(a[r], cur);
            }
            l >>= 1; r >>= 1;
        }
    }

    int get(int i, int h){
        i += n;
        vector<Node> sigma;
        while(i > 0){
            if (a[i].first.time != -1) sigma.push_back(a[i].first); 
            if (a[i].second.time != -1) sigma.push_back(a[i].second);
            i >>= 1;
        }
        sort(ALL(sigma), [] (Node a, Node b){return a.time < b.time;});
        for(auto i: sigma){
            if (i.op == 1){
                maximize(h, i.h);
            }
            else{
                minimize(h, i.h);
            }
        }
        return h;
    }
};

void buildWall(int n, int k, int op[], int left[], int right[],int height[], int finalHeight[]){
    SegmentTree st(n);
    for(int i = 0; i<k; ++i) st.update(left[i], right[i], i, op[i], height[i]);
    for(int i= 0; i<n; ++i) finalHeight[i] = st.get(i, 0);
}

// int main(void){
//     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//     SegmentTree st(5);
//     cout << st.get(1, 10) << "\n";
//     st.update(1, 3, 1, 1, 6);
//     st.update(1, 5, 2, 2, 5);
//     cout << st.get(1, 10) << "\n";
//     st.update(1, 3, 3, 1, 6);
//     cout << st.get(1, 10) << "\n";

//     return 0;
// }
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
3 Incorrect 1 ms 452 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 122 ms 13828 KB Output is correct
3 Correct 134 ms 7132 KB Output is correct
4 Correct 394 ms 22868 KB Output is correct
5 Correct 201 ms 23460 KB Output is correct
6 Correct 195 ms 21916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 2 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 2 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -