Submission #681668

#TimeUsernameProblemLanguageResultExecution timeMemory
681668kussssoWall (IOI14_wall)C++17
100 / 100
902 ms130676 KiB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e6 + 5;
const int inf = 1e9 + 7;

struct Node {
    int sum;
    int mx = inf;
    int mn = 0;
} 
st[N * 4];

void push (int x) {
    st[x * 2].mn = min(st[x].mx, max(st[x].mn, st[x * 2].mn));
    st[x * 2].mx = max(st[x].mn, min(st[x].mx, st[x * 2].mx));
    st[x * 2 + 1].mn = min(st[x].mx, max(st[x].mn, st[x * 2 + 1].mn));
    st[x * 2 + 1].mx = max(st[x].mn, min(st[x].mx, st[x * 2 + 1].mx));
    st[x].mn = 0;
    st[x].mx = inf;
}

void update (int l, int r, int h, int op, int x = 1, int L = 1, int R = N - 1) {
    if (L > r || R < l) return;
    if (l <= L && R <= r) {
        if (op == 1) {
            st[x].mn = max(st[x].mn, h);
            st[x].mx = max(st[x].mx, h);    
        }
        else {
            st[x].mn = min(st[x].mn, h);
            st[x].mx = min(st[x].mx, h);    
        }
    }
    else {
        push(x);
        int M = (L + R) / 2;
        update(l, r, h, op, x * 2, L, M);
        update(l, r, h, op, x * 2 + 1, M + 1, R);
    }
}

int get (int pos, int x = 1, int L = 1, int R = N - 1) {
    if (L == R) 
        return st[x].mn;
    
    push(x);
    
    int M = (L + R) / 2;
    if (pos <= M) 
        return get(pos, x * 2, L, M);
    
    return get(pos, x * 2 + 1, M + 1, R);    
}

void buildWall (int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
    // cout << st[0].mx << ' '<<st[0].mn << '\n';
    for (int i = 0; i < k; i++) {
        update(left[i] + 1, right[i] + 1, height[i], op[i]);
    }
    for (int i = 1; i <= n; i++) {
        finalHeight[i - 1] = get(i);
        // cout << get(i) << ' ';
    }
}

// signed main() {
    // ios_base::sync_with_stdio(0);
    // cin.tie(0);
//     
    // int op[] = {1, 2, 2, 1, 1, 2};
    // int left[] = {1, 4, 3, 0, 2, 6};
    // int right[] = {8, 9, 6, 5, 2, 7};
    // int height[] = {4, 1, 5, 3, 5, 0};
    // int finalHeight[10];
    // buildWall(10, 6, op, left, right, height, finalHeight);
//     
    // return 0;
// }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...