Submission #466682

#TimeUsernameProblemLanguageResultExecution timeMemory
466682jli12345Wall (IOI14_wall)C++14
100 / 100
1614 ms69688 KiB
#include <wall.h>
#include <bits/stdc++.h>
using namespace std;

pair<int, int> st[8000100];

pair<int, int> combine(pair<int, int> orig, pair<int, int> upd){
    if (upd.second > orig.first){
        return {upd.second, upd.second};
    } else if (upd.first < orig.second){
        return {upd.first, upd.first};
    } else {
        return {min(orig.first, upd.first), max(orig.second, upd.second)};
    }
}

void pushdown(int node){
    st[node*2] = combine(st[node*2], st[node]);
    st[node*2+1] = combine(st[node*2+1], st[node]);
}

void U(int node, int l, int r, int tl, int tr, pair<int, int> upd){
    if (l >tr || r < tl)
        return;
    if (l >= tl && r <= tr){
        st[node] = combine(st[node], upd);
        //cout << l << " " << r << " " << st[node].first << " " << st[node].second << "\n";
        return;
    }
    pushdown(node);
    int mid = (l+r)/2;
    U(node*2, l, mid, tl, tr, upd);
    U(node*2+1, mid+1, r, tl, tr, upd);
    st[node].first = max(st[node*2].first, st[node*2+1].first);
    st[node].second = min(st[node*2].second, st[node*2+1].second);
}

int Q(int node, int l, int r, int ind){
    if (l > ind || r < ind){
        return 0;
    }
    if (l == r){
        return st[node].first;
    }
    pushdown(node);
    int mid = (l+r)/2;
    st[node].first = max(st[node*2].first, st[node*2+1].first);
    st[node].second = min(st[node*2].second, st[node*2+1].second);
    return max(Q(node*2, l, mid, ind), Q(node*2+1, mid+1, r, ind));
}

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
    for (int i = 0; i < k; i++){
        if (op[i] == 1){
            U(1, 0, n-1, left[i], right[i], {0x3f3f3f3f, height[i]});
        } else {
            U(1, 0, n-1, left[i], right[i], {height[i], 0});
        }
    }
    for (int i = 0; i < n; i++){
        finalHeight[i] = Q(1, 0, n-1, 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...