답안 #1113653

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1113653 2024-11-17T00:27:16 Z sunboi 벽 (IOI14_wall) C++17
0 / 100
87 ms 40752 KB
#include <bits/stdc++.h>
using namespace std;


const int N = 2e5 + 1000;
vector<int> a(N);
vector<pair<long long, long long>> t(4 * N);
vector<int>lazy(4 * N);

void push(int v, int vl, int vr){
    if (vr < vl || v + 1 >= 4 * N) return;
    if (lazy[v] == 0) return;
    
    int vm = (vl + vr) / 2;
    push(2 * v, vl, vm);
    push(2 * v + 1, vm + 1, vr);
    
    //cout << v << ' ' << vl << ' ' << vr << ' ' << t[v].first << ' ' << t[v].second << endl;
    if (lazy[v] == 1){
        t[2 * v].first = min(max(t[2 * v].first, t[v].first), t[v].second);
    
    t[2 * v ].second = max(min(t[2 * v].second, t[v].second), t[v].first);
 
    t[2 * v + 1].first = min(max(t[2 * v + 1].first, t[v].first), t[v].second);
    
    t[2 * v + 1].second = max(min(t[2 * v + 1].second, t[v].second), t[v].first);
        lazy[2 * v] = lazy[2 * v + 1] = 1;
        lazy[v] = 0;
    }else if (lazy[v] == 2){
        t[2 * v].first = min(max(t[2 * v].first, t[v].first), t[v].second);
    
    t[2 * v ].second = max(min(t[2 * v].second, t[v].second), t[v].first);
 
    t[2 * v + 1].first = min(max(t[2 * v + 1].first, t[v].first), t[v].second);
    
    t[2 * v + 1].second = max(min(t[2 * v + 1].second, t[v].second), t[v].first);
        lazy[2 * v] = lazy[2 * v + 1] = 2;
        lazy[v] = 0;
    }
    

    t[2 * v + 1].first = min(max(t[2 * v + 1].first, t[v].first), t[v].second);
    
    t[2 * v + 1].second = max(min(t[2 * v + 1].second, t[v].second), t[v].first);
}


void build(int v, int vl, int vr) {
    if (vl == vr) {
        t[v] = {0, 0};
        return;
    }
    int vm = (vl + vr) / 2;
    
    build(2 * v, vl, vm);
    build(2 * v + 1, vm + 1, vr);
    
    t[v] = {max(t[2 * v].first, t[2 * v + 1].first), min(t[2 * v].second, t[2 * v + 1].second)};
}

void update(int v, int vl, int vr, int l, int r, long long x){
    if (vl > r || vr < l) return;
    
    if (vl != vr)push(v, vl ,vr);
    if (vl >= l && vr <= r){
        t[v] = {max(t[v].first, x), max(t[v].second, x)};
        lazy[v] = 1;
        return;
    }
    
    int vm = (vl + vr) / 2;
    
    update(2 * v, vl, vm, l, r, x);
    update(2 * v + 1, vm + 1, vr, l, r, x);

    t[v] = {max(t[2 * v].first, t[2 * v + 1].first), min(t[2 * v].second, t[2 * v + 1].second)};
}

void update2(int v, int vl, int vr, int l, int r, long long x){
    if (vl > r || vr < l) return;
    
    //cout << "METIDOS " << v << ' ' << vl << ' ' << vr << ' ' << l << ' ' << r << ' ' << x << endl;
    if (vl != vr)push(v, vl ,vr);
    if (vl >= l && vr <= r){
        
        t[v] = {min(t[v].first, x), min(t[v].second, x)};
        
        lazy[v] = 2;
        
        return;
    }
    
    
    int vm = (vl + vr) / 2;
    
    update2(2 * v, vl, vm, l, r, x);
    update2(2 * v + 1, vm + 1, vr, l, r, x);

    t[v] = {max(t[2 * v].first, t[2 * v + 1].first), min(t[2 * v].second, t[2 * v + 1].second)};
}

int get(int v, int vl, int vr, int x){
    if (vl > x || vr < x) return 0;
    
    if (vl != vr)push(v, vl ,vr);
    
    if (vr <= x && x <= vl){
        return t[v].first;
    }
    
    int vm = (vl + vr) / 2;
    
    return max(get(2 * v, vl, vm, x), get(2 * v + 1, vm + 1, vr, x));
    
}

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){

    for (int i = 0; i < n; i++){
        a[i] = 0;
    }
    build(1, 0, n - 1);
    for (int i = 0; i < k; i++){
        if (op[i] == 1){
            update(1, 0, n - 1, left[i], right[i], height[i]);
        }else update2(1, 0, n - 1, left[i], right[i], height[i]);
        
    }
    for (int i = 0; i < n; i++){
        
        finalHeight[i] = get(1, 0, n - 1, i);
    }

    return;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 16720 KB Output is correct
2 Correct 5 ms 16840 KB Output is correct
3 Runtime error 28 ms 34040 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 16720 KB Output is correct
2 Correct 87 ms 24608 KB Output is correct
3 Runtime error 71 ms 40752 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 16720 KB Output is correct
2 Correct 4 ms 16976 KB Output is correct
3 Runtime error 27 ms 34044 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 16720 KB Output is correct
2 Correct 4 ms 16976 KB Output is correct
3 Runtime error 27 ms 34056 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -