This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "wall.h"
#include <bits/stdc++.h>
using namespace std;
struct node{
int mn;
int mx;
node(){
mn = 1e9;
mx = -1e9;
}
};
const int N = 2e6 + 3e2;
node t[4 * N];
void chmin(int &var, int val){
var = min(var, val);
}
void chmax(int &var, int val){
var = max(var, val);
}
void push(int v){
if (t[v].mn != 1e9){
chmin(t[v + v].mn, t[v].mn);
chmin(t[v + v].mx, t[v].mn);
chmin(t[v + v + 1].mn, t[v].mn);
chmin(t[v + v + 1].mx, t[v].mn);
t[v].mn = 1e9;
}
if (t[v].mx != -1e9){
chmax(t[v + v].mn, t[v].mx);
chmax(t[v + v].mx, t[v].mx);
chmax(t[v + v + 1].mn, t[v].mx);
chmax(t[v + v + 1].mx, t[v].mx);
t[v].mx = -1e9;
}
}
void update(int v, int tl, int tr, int l, int r, int val, char type){
if (l <= tl && tr <= r){
if (type == '+'){
chmax(t[v].mn, val);
chmax(t[v].mx, val);
} else {
chmin(t[v].mn, val);
chmin(t[v].mx, val);
}
return;
}
if (tl > r || tr < l) return;
push(v);
int tm = (tl + tr) >> 1;
update(v + v, tl, tm, l, r, val, type);
update(v + v + 1, tm + 1, tr, l, r, val, type);
}
node get(int v, int tl, int tr, int pos){
if (tl == tr) return t[v];
push(v);
int tm = (tl + tr) >> 1;
if (pos <= tm) return get(v + v, tl, tm, pos); else
return get(v + v + 1, tm + 1, tr, pos);
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
for (int i = 0; i < n; i++){
update(1, 0, n - 1, i, i, 0, '+');
}
for (int i = 0; i < k; i++){
update(1, 0, n - 1, left[i], right[i], height[i], op[i] == 1 ? '+' : '-');
}
for (int i = 0; i < n; i++){
finalHeight[i] = get(1, 0, n - 1, i).mx;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |