Submission #237888

#TimeUsernameProblemLanguageResultExecution timeMemory
237888wiwihoWall (IOI14_wall)C++14
100 / 100
901 ms99424 KiB
#include "wall.h"

//#define NDEBUG

#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define iceil(a, b) ((a + b - 1) / b)
#define tomax(a, b) (a = max(a, b))
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}

//#define TEST

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

struct Node{
    int l = -1, r = -1, mx = -MAX, mn = MAX;
};

vector<Node> st;
int ts = 0;

int build(int l, int r){
    int id = ts++;
//    cerr << l << " " << r << " " << id << "\n";
    if(l == r) return id;
    int m = (l + r) / 2;
    st[id].l = build(l, m);
    st[id].r = build(m + 1, r);
    return id;
}

void add(int id, int v){
    st[id].mx = max(st[id].mx, v);
    st[id].mn = max(st[id].mn, v);
}

void remove(int id, int v){
    st[id].mx = min(st[id].mx, v);
    st[id].mn = min(st[id].mn, v);
}

void push(int id){
    add(st[id].l, st[id].mx);
    add(st[id].r, st[id].mx);
    st[id].mx = -MAX;
    remove(st[id].l, st[id].mn);
    remove(st[id].r, st[id].mn);
    st[id].mn = MAX;
}

void modifyadd(int l, int r, int v, int L, int R, int id){
//    cerr << l << " " << r << " " << L << " " << R << " " << id << "\n";
    if(l == L && r == R){
        add(id, v);
        return;
    }
    push(id);
    int M = (L + R) / 2;
    if(r <= M) modifyadd(l, r, v, L, M, st[id].l);
    else if(l > M) modifyadd(l, r, v, M + 1, R, st[id].r);
    else{
        modifyadd(l, M, v, L, M, st[id].l);
        modifyadd(M + 1, r, v, M + 1, R, st[id].r);
    }
}

void modifyremove(int l, int r, int v, int L, int R, int id){
    if(l == L && r == R){
        remove(id, v);
        return;
    }
    push(id);
    int M = (L + R) / 2;
    if(r <= M) modifyremove(l, r, v, L, M, st[id].l);
    else if(l > M) modifyremove(l, r, v, M + 1, R, st[id].r);
    else{
        modifyremove(l, M, v, L, M, st[id].l);
        modifyremove(M + 1, r, v, M + 1, R, st[id].r);
    }
}

void ans(int l, int r, int id, int finalHeight[]){
    if(l == r){
        finalHeight[l] = max(st[id].mx, min(st[id].mn, 0));
        return;
    }
    push(id);
    int m = (l + r) / 2;
    ans(l, m, st[id].l, finalHeight);
    ans(m + 1, r, st[id].r, finalHeight);
}

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

    st.resize(2 * n);
    build(0, n - 1);

    for(int i = 0; i < k; i++){
        if(op[i] == 1) modifyadd(left[i], right[i], height[i], 0, n - 1, 0);
        else modifyremove(left[i], right[i], height[i], 0, n - 1, 0);
    }

    ans(0, n - 1, 0, finalHeight);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...