Submission #593899

#TimeUsernameProblemLanguageResultExecution timeMemory
593899Do_you_copyWall (IOI14_wall)C++17
100 / 100
1667 ms153864 KiB
#include <bits/stdc++.h>
#define taskname "test"
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using pil = pair <int, ll>;
using pli = pair <ll, int>;
using pll = pair <ll, ll>;
using ull = unsigned ll;
mt19937 Rand(chrono::steady_clock::now().time_since_epoch().count());

ll min(const ll &a, const ll &b){
    return (a < b) ? a : b;
}

ll max(const ll &a, const ll &b){
    return (a > b) ? a : b;
}

//const ll Mod = 1000000009;
//const ll Mod2 = 999999999989;
//only use when required
const int maxN = 2e6 + 1;
const int inf = 0x3f3f3f3f;
int n, k;

struct TNode{
    int mmax, mmin, lazymax, lazymin;
    TNode() : mmax(0), mmin(0), lazymax(-1), lazymin(inf){}
};

TNode st[maxN * 4];

void addmin(int id, int h){
    if (st[id].lazymin < h) return;
    st[id].lazymin = h;
    st[id].lazymax = min(st[id].lazymax, h);
    st[id].mmax = min(st[id].mmax, h);
    st[id].mmin = min(st[id].mmin, h);
}

void addmax(int id, int h){
    if (st[id].lazymax > h) return;
    st[id].lazymax = h;
    st[id].lazymin = max(st[id].lazymin, h);
    st[id].mmax = max(st[id].mmax, h);
    st[id].mmin = max(st[id].mmin, h);
}

void pull(int id){
    addmax(id * 2, st[id].lazymax);
    addmax(id * 2 + 1, st[id].lazymax);
    addmin(id * 2, st[id].lazymin);
    addmin(id * 2 + 1, st[id].lazymin);
    st[id].lazymax = -1;
    st[id].lazymin = inf;
}

void update(int id, int i, int j, int h, int t, int l = 0, int r = n - 1){
    if (r < i || l > j) return;
    if (i <= l && r <= j){
        if (t) addmin(id, h);
        else addmax(id, h);
        return;
    }
    pull(id);
    int mid = (l + r) / 2;
    update(id * 2, i, j, h, t, l, mid);
    update(id * 2 + 1, i, j, h, t, mid + 1, r);
    st[id].mmax = max(st[id * 2].mmax, st[id * 2 + 1].mmax);
    st[id].mmin = min(st[id * 2].mmin, st[id * 2 + 1].mmin);
}

int get(int id, int i, int l = 0, int r = n - 1){
    if (l == r){
        assert(st[id].mmax == st[id].mmin);
        return st[id].mmax;
    }
    //if (i == 3) cerr << l << " " << r << " " << st[id].lazymax << ":\n";
    pull(id);
    int mid = (l + r) / 2;
    if (mid >= i) return get(id * 2, i, l, mid);
    else return get(id * 2 + 1, i, mid + 1, r);
}

void buildWall(int N, int K, int op[], int left[], int right[], int height[], int finalHeight[]){
    n = N, k = K;
    for (int i = 0; i < k; ++i){
        update(1, left[i], right[i], height[i], op[i] - 1);
    }
    for (int i = 0; i < n; ++i){
        finalHeight[i] = get(1, i);
    }
    return;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...