Submission #697824

#TimeUsernameProblemLanguageResultExecution timeMemory
697824Elvin_FritlWall (IOI14_wall)C++17
100 / 100
940 ms130712 KiB
#include<bits/stdc++.h>
#include "wall.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[]) {
    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);
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...