This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* R */
#include<bits/stdc++.h>
#include "wall.h"
#define ll long long
#define vl vector<ll>
#define pll pair<ll,ll>
#define in insert
#define fi first
#define se second
#define all(v) v.begin(), v.end()
using namespace std;
const ll sz = 2e6+6;
const ll inf = 1000000000000000;
vector<array<ll, 2>> st;
ll res[sz];
void comp(ll x1, ll x2){
st[x2][0] = min(st[x1][1], max(st[x2][0], st[x1][0]));
st[x2][1] = max(st[x1][0], min(st[x2][1], st[x1][1]));
}
void push(ll v, ll l, ll r){
if(l == r){return ;}
comp(v, v*2);
comp(v, v*2+1);
st[v] = {0, inf};
}
void update(ll v, ll tl, ll tr, ll l, ll r, ll val, ll type){
if(tl > r || tr <l){return ;}
if(tl >= l && tr <= r){
if(type == 1){
st[v][0] = max(st[v][0], val);
st[v][1] = max(st[v][1], val);
}
else{
st[v][0] = min(st[v][0], val);
st[v][1] = min(st[v][1], val);
}
return ;
}
push(v, tl, tr);
ll tm = (tl+tr)>>1;
update(v*2, tl, tm, l, r, val, type);
update(v*2+1, tm+1, tr, l, r, val, type);
}
void trav(ll v, ll tl, ll tr){
if(tl == tr){
res[tl - 1] = st[v][0];
return ;
}
push(v, tl, tr);
ll tm = (tl + tr)>>1;
trav(v*2, tl, tm);
trav(v*2+1, tm+1, tr);
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
ll i, j, z = 0;
st.assign(sz*4, {0, inf});
for(i=0;i<k;i++){
update(1, 1, n, left[i] + 1, right[i] + 1, height[i], op[i]);
}
trav(1, 1, n);
for(i=0;i<n;i++){
//cout << res[i] << ' ';
finalHeight[i] = max(z, res[i]);
}
}
/*
10 6
1 1 8 4
0 4 9 1
0 3 6 5
1 0 5 3
1 2 2 5
0 6 7 0
*/
Compilation message (stderr)
wall.cpp: In function 'void buildWall(int, int, int*, int*, int*, int*, int*)':
wall.cpp:55:11: warning: unused variable 'j' [-Wunused-variable]
55 | ll i, j, z = 0;
| ^
# | 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... |