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>
#define pii pair <int,int>
#define f first
#define s second
#define pb push_back
#define leftt h*2,l,(l + r)/2
#define rightt h*2+1,(l + r)/2 + 1,r
using namespace std;
const int N = 2e6 + 3;
vector <pii> lz[4*N];
pii t[4*N];
void chn(int h,int H,int tp){
if (tp == 1){
//max -> H
if (t[h].f < H){
t[h].f = H;
t[h].s = max(t[h].s,H);
}
}else{
//min -> H
if (t[h].s > H){
t[h].s = H;
t[h].f = min(t[h].f,H);
}
}
}
void push(int h){
if (!lz[h].size()) return;
for (auto [H,tp]: lz[h]){
chn(h*2,H,tp);
chn(h*2+1,H,tp);
lz[h*2].pb({H,tp});
lz[h*2+1].pb({H,tp});
}
lz[h].clear();
}
void upd(int h,int l,int r,int L,int R,int H,int tp){
if (r < L || R < l) return ;
if (L <= l && r <= R){
if (tp == 1){
//max -> H
if (t[h].f < H){
t[h].f = H;
t[h].s = max(t[h].s,H);
}
}else{
//min -> H
if (t[h].s > H){
t[h].s = H;
t[h].f = min(t[h].f,H);
}
}
lz[h].pb({H,tp});
return;
}
push(h);
upd(leftt,L,R,H,tp);
upd(rightt,L,R,H,tp);
}
int get(int h,int l,int r,int idx){
if (l == r) return t[h].f;
push(h);
if (idx > (l + r)/2) return get(rightt,idx);
return get(leftt,idx);
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
for (int i = 0; i < k; i++){
left[i]++;
right[i]++;
upd(1,1,n,left[i],right[i],height[i],op[i]);
}
for (int i = 0; i < n; i++){
finalHeight[i] = get(1,1,n,i+ 1);
}
return;
}
# | 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... |